Combination of two rules into one

Hi,
this one is not working

rule "PV CB1"
when
Item Luminance changed

then
val Number cur_lum = Luminance.state as Number
val Number setpOn = 7500
val Number setpOff = 5000
if (cur_lum > setpOn) {
	if (DA2_RM.state == OPEN) {
    		DA2_DA.sendCommand(ON)
    		sendMail("js@email.com", "Photovoltaic ON", "Circuitbraker ON !")
 				               }
    		           }
else if (cur_lum < setpOff) {
	if (DA2_RM.state == CLOSED) {
    		DA2_DA.sendCommand(OFF)
   		    sendMail("js@email.com", "Photovoltaic OFF", "Circuitbraker OFF !")
   				                 }
                           }
end

This separated two are working

rule "PV CB2"
when
Item Luminance changed

then
val Number cur_lum = Luminance.state as Number
val Number setpOn = 7500
val Number setpOff = 5000
if (cur_lum > setpOn) {DA2_DA.sendCommand(ON)}
else if (cur_lum < setpOff) {DA2_DA.sendCommand(OFF)}
end

rule "PV CB send email.com"
when
    Item DA2_RM changed
then
if (DA2_RM.state == CLOSED) {sendMail("js@email.com", "Photovoltaic ON", "Circuitbraker ON !")}
else
    sendMail("js@email.com", "Photovoltaic OFF", "Circuitbraker OFF !")
end

Why please. Thanks.

For one thing, the email addresses are different in the 2 examples. The working one is to email.cz and the combined one is email.com`.

If you are trying to use bogus addresses, that is the purpose of example.com and other example domains.

Sorry misstyping from me, just email example. Command together with mail sending (also two reactions) together are not working. Also maybe RM.state check is the reason.
DA2_DA is a command to relais unit,
DA2_RM is a state signal from relais unit.

If DA2_RM state is OPEN, than only at this state can be send a command ON.
Opposite, iff DA2_RM state is CLOSED, than only at this state can be send a command OFF.

If no control trough RM state is calculated, than a repetitive command is send and this is not necessary.

Pair of {} seem to be correct, or ?

What’s wrong with having two rules? It doesn’t cost you anything.
I don’t know what you’re doing exactly, but separate rules for separate tasks seems like a good idea.

Here, does rule "PV CB send email.com" do what you want - and send a mail when the relay changes, whatever the reason? If so, leave it alone.

We don’t know what you want to happen, so you have to tell us more about what that means.

You can find out what is going on in your rule by using temporary logInfo().
Here’s an example, I’m guessing at what you want it to do though.

rule "PV CB2"
when
   Item Luminance changed
then
   val Number cur_lum = Luminance.state as Number
   logInfo("test", "Rule begins with value " + cur_lum.toString)
   val Number setpOn = 7500
   val Number setpOff = 5000
   logInfo("test", "Contact state is " + DA2_RM.state.toString)
   if (cur_lum > setpOn && DA2_RM.state == OPEN) {
      DA2_DA.sendCommand(ON)
   } else if (cur_lum < setpOff && DA2_RM.state == CLOSED) {
      DA2_DA.sendCommand(OFF)
   } else {
      logInfo("test", "No action this time")
   }
end

Thank you for logInfo.
Is this subsequence correct ?

if (cur_lum > setpOn) {
	if (DA2_RM.state == OPEN) {
    		DA2_DA.sendCommand(ON)
    		sendMail("js@email.com", "Photovoltaic ON", "Circuitbraker ON !")
 				               }
    		           }

I don’t know. Try it and tell us the results.

OK. Thanks for && inside. I will send result.
I would send two or more “command lines” between if end next else if.