|
Post by chrisinkc on Feb 24, 2016 3:24:45 GMT
I am having trouble with one of my rules. This is code borrowed from lewishollow's example.rules file.
I want to send a notification when the lights go on and again when the lights go off. Here is my rule:
rule "Garage Lights"
when
Item itm_node2_light_mqtt received update
then
var lightThreshold = 200
var triggeredLightState = itm_node2_light_mqtt.state
if (triggeredLightState > lightThreshold && itm_node2_light_state != ON)
{
sendCommand(itm_node2_light_state, ON)
postUpdate(itm_node2_light_triggered_value, triggeredLightState)
sendNotification("chrisdawsonkc@gmail.com", "Garage Light is now ON!")
}
else
{
if (triggeredLightState > lightThreshold && itm_node2_light_state == ON)
{
sendCommand(itm_node2_light_state, ON)
postUpdate(itm_node2_light_triggered_value, triggeredLightState)
}
else
{
if (triggeredLightState <= lightThreshold && itm_node2_light_state == ON)
{
sendCommand(itm_node2_light_state, OFF)
sendNotification("chrisdawsonkc@gmail.com", "Garage Light is now OFF!")
}
else
{
sendCommand(itm_node2_light_state, OFF)
}
}
}
postUpdate(itm_node2_light_threshold, lightThreshold)
end
When I turn on the lights, I get the Lights On notification as expected. However, I continue to get the Lights On notification every few seconds until I turn the lights off. I do not ever receive the notification that the lights are off.
Can anybody see what is wrong with my IF Then statement?
|
|
|
Post by greginkansas on Feb 24, 2016 12:18:57 GMT
Use a proxy item to switch item once. rule "front_porch_occupancy Motion Trigger" when Item node14motion received update ON //try to get motion right // Item node14motion changed from OFF to ON then if (node6Light_intensity.state >= 150) { // light level postUpdate(front_porch_occupancy, ON) } if (allsoundsoff.state == ON) { squeezeboxPlayUrl("livingroom","file://localhost/usr/share/openhab/sounds/doorbell.mp3") } end rule "front_porch_occupancy Absence" when Item node14motion changed from ON to OFF then tfront_porch_occupancy?.cancel tfront_porch_occupancy = createTimer(now.plusMinutes(2)) [| postUpdate(front_porch_occupancy, OFF) ] end rule "front_porch_occupancyTrigger" when Item front_porch_occupancy changed from OFF to ON then sendCommand(Insteon_switch_1, ON) logInfo("front_porch_occupancy", "bathroom on") tfront_porch_occupancy?.cancel tfront_porch_occupancy = null end rule "front_porch_occupancy_Absence" when Item front_porch_occupancy changed from ON to OFF then logInfo("front_porch_occupancy", "bathroom off") // postUpdate(Insteon2, OFF) sendCommand(Insteon_switch_1, OFF) end
|
|
|
Post by greginkansas on Feb 24, 2016 21:01:09 GMT
This is a shorter proxy rule
rule "Front porch light on Dining Room Light level proxy" when Item node6Light_intensity received update then if (node6Light_intensity.state >= 245) { // low light level postUpdate(its_morning_porch_light, ON) } else { postUpdate(its_morning_porch_light, OFF) } end rule "Front porch light on Dining Room Light level decide" when Item its_morning_porch_light changed then if (its_morning_porch_light.state == ON) { sendCommand(porch_light, 2) logInfo("Porch light","porch light on") } if (its_morning_porch_light.state == OFF) { sendCommand(porch_light, OFF) logInfo("Porch light","porch light off") } end
|
|
|
Post by chrisinkc on Feb 25, 2016 1:09:21 GMT
Thanks Greg! Your last post worked perfectly.
|
|