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
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.
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