IPS_KERNELSTARTED / IPS_KERNELSHUTDOWN

Is it possible to use IPS_KERNELSTARTED / IPS_KERNELSHUTDOWN and use them as, or convert them to „online“ / „offline“ messages? Can I use them in a flow (or PHP) script?
I want to update the MQTT availability topics using these variables.

It’s not exactly IPS_KERNELSTARTED and IPS_KERNELSHUTDOWN, but in the Event Control, you can select automations to be executed on start and shutdown. I’d guess under the hood that’s pretty much the same time as those messages.

1 „Gefällt mir“

That works. I assumed that creating a PHP script would be easier and less work. Maybe using something like (IPS_GetKernelRunlevel();), or something along those lines. :wink:

<?php
// Get the current kernel runlevel
$runlevel = IPS_GetKernelRunlevel();

// Define your actions based on the runlevel
switch ($runlevel) {
    case KR_CREATE:
        IPS_LogMessage("Kernel Runlevel", "Kernel is being created.");
        // Add your action here
        break;
    
    case KR_INIT:
        IPS_LogMessage("Kernel Runlevel", "Kernel is initializing.");
        // Add your action here
        break;
    
    case KR_READY:
        IPS_LogMessage("Kernel Runlevel", "Kernel is ready and running.");
        // Add your action here
        RequestAction(14527, "online");
        break;
    
    case KR_UNINIT:
        IPS_LogMessage("Kernel Runlevel", "Kernel is shutting down.");
        // Add your action here
        RequestAction(14527, "offline");
        break;
    
    case KR_SHUTDOWN:
        IPS_LogMessage("Kernel Runlevel", "Kernel has been completely shut down.");
        // Add your action here
        break;
    
    default:
        IPS_LogMessage("Kernel Runlevel", "Unknown runlevel: " . $runlevel);
        // Add your action here
        break;

// Additional logic if needed
?>

@Dr.Niels I tested the startup script solution, but the results have been inconsistent. I think the startup script starts too soon. Sometimes it works, but other times it doesn’t. Running the script manually always succeeds. Do you have any other suggestions? Thanks!

P.S. A „sleep()“ function at the start of the script helps.

This the message, that we start the „Startup“ script on. Therefore it should work. What are you trying to do in the startup script and which error do you get, when it fails?

paresy

Hi @paresy ,

Not really a error, but it looks like the actions are executed before everything is avalaible. The „sleep()“ function prevents this. The script updates all MQTT Clients Devices after a reboot of Symcon. I think a RETAIN flag would make this workaround unnecessary (for the updated STATUS values). Maybe I can trigger a warning if I disable the „sleep()“ function.

<?php

//Start writing your code here
sleep(3);
IPS_RunScript(31735);
IPS_RunScript(16186);
<?php

//Start writing your code here
RequestAction(14527, "online");
RequestAction(48299, "online");
RequestAction(49620, "online");
RequestAction(59329, "online");
RequestAction(16337, "online");
RequestAction(45518, "online");
RequestAction(16618, "online");
RequestAction(22665, "online");
RequestAction(15445, "online");
RequestAction(57062, "online");
RequestAction(58723, "online");
RequestAction(30027, "online");
RequestAction(59487, "online");
RequestAction(40710, "online");
RequestAction(36498, "online");
RequestAction(42163, "online");
RequestAction(32118, "online");
RequestAction(46180, "online");
RequestAction(36167, "online");
RequestAction(16791, "online");
RequestAction(39433, "online");
RequestAction(57943, "online");
RequestAction(13691, "online");
RequestAction(30199, "online");
RequestAction(20937, "online");
RequestAction(24069, "online");
RequestAction(50861, "online");
RequestAction(39573, "online");
RequestAction(14999, "online");
RequestAction(32479, "online");
RequestAction(58301, "online");
RequestAction(23860, "online");
RequestAction(48585, "online");
RequestAction(10256, "online");
RequestAction(42690, "online");
RequestAction(20468, "online");
RequestAction(38029, "online");
RequestAction(14574, "online");
RequestAction(35970, "online");
RequestAction(52236, "online");
RequestAction(16864, "online");
RequestAction(42176, "online");
RequestAction(11058, "online");
RequestAction(13932, "online");
RequestAction(15090, "online");
RequestAction(17286, "online");
<?php

//Start writing your code here
RequestAction(44206, GetValue(55465));
RequestAction(22079, GetValue(38023));
RequestAction(24671, GetValue(26168));
RequestAction(11031, GetValue(59469));
RequestAction(24843, GetValue(25788));
RequestAction(53814, GetValue(13104));
RequestAction(42668, GetValue(51945));
RequestAction(54595, GetValue(58035));
RequestAction(12240, GetValue(28023));
RequestAction(28672, GetValue(26900));
RequestAction(26192, GetValue(19200));
RequestAction(12379, GetValue(23503));
RequestAction(48602, GetValue(29480));
RequestAction(39531, GetValue(19684));
RequestAction(46623, GetValue(37375));
RequestAction(34244, GetValue(25635));
RequestAction(24997, GetValue(39044));
RequestAction(48483, GetValue(27553));
RequestAction(33041, GetValue(41017));
RequestAction(35274, GetValue(41565));
RequestAction(52688, GetValue(37908));
RequestAction(47602, GetValue(17536));
RequestAction(12149, GetValue(53561));
RequestAction(53787, GetValue(59364));
RequestAction(10694, GetValue(17720));
RequestAction(12878, GetValue(22678));
RequestAction(49413, GetValue(23441));
RequestAction(56740, GetValue(34084));
RequestAction(54722, GetValue(59452));
RequestAction(21452, GetValue(44976));
RequestAction(36658, GetValue(37900));
RequestAction(53816, GetValue(53052));
RequestAction(33449, GetValue(17897));
RequestAction(11438, GetValue(33091));
RequestAction(51664, GetValue(24229));
RequestAction(55612, GetValue(14134));
RequestAction(57970, GetValue(38281));
RequestAction(12972, GetValue(50719));
RequestAction(49941, GetValue(35959));
RequestAction(40433, GetValue(27776));
RequestAction(10764, GetValue(22373));
RequestAction(26766, GetValue(13667));
RequestAction(47691, GetValue(16453));
RequestAction(53720, GetValue(49706));
RequestAction(10056, GetValue(11948));
RequestAction(41132, GetValue(20719));
RequestAction(35709, GetValue(34021));
RequestAction(43586, GetValue(34935));
RequestAction(31780, GetValue(43112));
RequestAction(30439, GetValue(13386));
RequestAction(40842, GetValue(46171));
RequestAction(47740, GetValue(17886));
RequestAction(17362, GetValue(43834));
RequestAction(49559, GetValue(18096));
RequestAction(56678, GetValue(17573));
RequestAction(59299, GetValue(22959));
RequestAction(29761, GetValue(19382));
RequestAction(35749, GetValue(23409));

Okey. The MQTT Client might not have connected/authenticated directly after the KR_READY. Therefore the sleep is a good workaround. The Retain Fix will be available in the next 1-2 hours.

paresy

That seems like a solid explanation of what’s happening. (A one-second delay is sufficient, and it could be even less.)

I am waiting with anticipation :wink: