Rule to check status and change it if necessary (SOLVED)

Hello

I have several street lights managed with OH2 work with building Astro do not give almost problems only occasionally I find two lights that suddenly turn off if you see why in the registry or anywhere else create a rule so that Check the status and if they are off, turn them on but it’s not going, you could help me,
a greeting
PD.- Sorry for my English.

 rule "comprobacion luces"
when
     Channel 'astro:sun:home:set#event' triggered START 
   then
    if (Lucesnorte.state == OFF && Puerta_atras.state == OFF)
		
			logInfo("COMPROBACION LUCES", "ENCENDIDA")
			Lucesnorte.sendCommand(ON)
			Puerta_atras.sendCommand(ON)
        

end

TWO errors
You want an OR check
and the if syntax needs a {}

 rule "comprobacion luces"
when
    Channel 'astro:sun:home:set#event' triggered START
then
    if (Lucesnorte.state == OFF || Puerta_atras.state == OFF) {
        logInfo("COMPROBACION LUCES", "ENCENDIDA")
        Lucesnorte.sendCommand(ON)
        Puerta_atras.sendCommand(ON)
    }
end

Do you use VS Code to write your rules?

Ok thank you, I will try your advice. I can not still use Vscode because I have problems with Windows 10 and my raspberry

I’m sorry to tell you that it does not work tonight he went back to turn off a light and the rule did not turn it on

?? The rule you posted has the Trigger " Channel ‘astro:sun:home:set#event’ triggered START ", so this rule will only Trigger once a day when the sun-set event starts. In order the have a rule running on a changed Event of an item (for example: turn off a light) you need to set the trigger on the changed event of that item!

So, what is it that you really want to do.

You were not clear on what you want to achieve
I think that what you want is that AFTER sunset, if one of the two lights turns off then turn it back on.

You need to look at this design pattern:

that’s just what I want to do I’ll look at the link and see if I find out something

Hello, from what I see I would have to do a cron expression first in the when and then in the then variable that if I check the lights after dark but I do not know how to do it, I have read the links and I have not seen anything, a greeting and thanks for help

I expect you realise this is a band-aid, might be better to find out why your lights are turning off unexpectedly?

One way to set your rule up would be to use the ‘time of day’ pattern to set up something that indicates if it dark.
Then a rule triggered by cron every ten minutes or every hour or whatever, that checs to see if it is dark, and if it is make sure the lights are on.

Hello, in that you are right but I lost too much time in looking for the fault and I have not found it.
With this rule if the check works and if it is turned off, in addition to the rule, create an Item that tells the system when it is night, thank you very much

rule "comprobacion luces"
when
   Time cron "0 0/10 * * * ?"
then
	if(Sunrise_Event_Atardecer.state == ON) {
    		if (Lucesnorte.state == OFF || Puerta_atras.state == OFF) {
        		logInfo("COMPROBACION LUCES", "ENCENDIDA")
        		Lucesnorte.sendCommand(ON)
        		Puerta_atras.sendCommand(ON)
    }
}
end

Good, well done
Please mark the thread as solved, thanks