Hi,
I want to control a motor (for a blind) with alexa. I have build an item, a thing, a python script, a sitemap and the following rules (big thanks to rlkoshak and Josar):
rule "Motor 1"
when
// FENSTER means window
Item FENSTER changed
then
logInfo("Jalousie", "FENSTER changed -> FENSTER.state: " + FENSTER.state.toString + " MOTOR_STATE: " + MOTOR_STATE.state.toString)
MOTOR_STATE.postUpdate(FENSTER.state.toString)
MOTOR.sendCommand(FENSTER.state.toString)
end
rule "Motor 2"
when
Item MOTOR_STATE changed
then
logInfo("Jalousie", "MOTOR_STATE changed -> FENSTER.state: " + FENSTER.state.toString + " MOTOR_STATE: " + MOTOR_STATE.state.toString)
MOTOR.postUpdate(MOTOR_STATE.state.toString)
MOTOR.sendCommand(MOTOR_STATE.state.toString)
end
That works as expected.
BUT: The blind can manually changed from open to closed and reverse. So, when I send a command ON and state is ON, it should start the script again.
But it didn’t. So I changed the rules to …
rule "Motor ON"
when
Item FENSTER received command ON
then
logInfo("Jalousie", "FENSTER changed -> FENSTER.state: " + FENSTER.state.toString + " MOTOR_STATE: " + MOTOR_STATE.state.toString)
logInfo("Jalousie", "FENSTER received command: " + receivedCommand.toString)
MOTOR_STATE.postUpdate(FENSTER.state.toString)
MOTOR.sendCommand(ON)
end
rule "Motor OFF"
when
Item FENSTER received command OFF
then
logInfo("Jalousie", "FENSTER changed -> FENSTER.state: " + FENSTER.state.toString + " MOTOR_STATE: " + MOTOR_STATE.state.toString)
logInfo("Jalousie", "FENSTER received command: " + receivedCommand.toString)
MOTOR_STATE.postUpdate(FENSTER.state.toString)
MOTOR.sendCommand(OFF)
end
rule "Motor State"
when
Item MOTOR_STATE changed
then
logInfo("Jalousie", "MOTOR_STATE changed -> FENSTER.state: " + FENSTER.state.toString + " MOTOR_STATE: " + MOTOR_STATE.state.toString)
MOTOR.postUpdate(MOTOR_STATE.state.toString)
MOTOR.sendCommand(MOTOR_STATE.state.toString)
end
The events.log shows:
2018-03-28 20:34:04.603 [ome.event.ItemCommandEvent] - Item ‘MOTOR’ received command OFF
2018-03-28 20:34:04.612 [vent.ItemStateChangedEvent] - MOTOR_STATE changed from to OFF
2018-03-28 20:34:04.653 [ome.event.ItemCommandEvent] - Item ‘MOTOR’ received command OFF
2018-03-28 20:34:04.659 [vent.ItemStateChangedEvent] - MOTOR changed from to OFF
2018-03-28 20:34:12.974 [ome.event.ItemCommandEvent] - Item ‘FENSTER’ received command ON
2018-03-28 20:34:13.002 [vent.ItemStateChangedEvent] - FENSTER changed from OFF to ON
2018-03-28 20:34:13.062 [vent.ItemStateChangedEvent] - MOTOR_STATE changed from OFF to ON
2018-03-28 20:34:13.065 [ome.event.ItemCommandEvent] - Item ‘MOTOR’ received command ON
2018-03-28 20:34:13.111 [vent.ItemStateChangedEvent] - MOTOR changed from OFF to ON
2018-03-28 20:34:13.116 [ome.event.ItemCommandEvent] - Item ‘MOTOR’ received command ON
2018-03-28 20:34:22.047 [ome.event.ItemCommandEvent] - Item ‘FENSTER’ received command ON
2018-03-28 20:34:22.113 [ome.event.ItemCommandEvent] - Item ‘MOTOR’ received command ON
2018-03-28 20:34:27.690 [vent.ItemStateChangedEvent] - MOTOR changed from ON to
2018-03-28 20:34:27.696 [vent.ItemStateChangedEvent] - MOTOR_STATE changed from ON to
2018-03-28 20:34:27.721 [ome.event.ItemCommandEvent] - Item ‘MOTOR’ received command
The openhab.logs shows
//rule “Motor OFF”
2018-03-28 20:34:04.590 [INFO ] [ipse.smarthome.model.script.Jalousie] - FENSTER received command: OFF
//rule “Motor Stater§”
2018-03-28 20:34:04.638 [INFO ] [ipse.smarthome.model.script.Jalousie] - MOTOR_STATE changed -> FENSTER.state: OFF MOTOR_STATE: OFF
//rule “Motor OFF”
2018-03-28 20:34:13.017 [INFO ] [ipse.smarthome.model.script.Jalousie] - FENSTER changed -> FENSTER.state: ON MOTOR_STATE: OFF
2018-03-28 20:34:13.028 [INFO ] [ipse.smarthome.model.script.Jalousie] - FENSTER received command: ON
//rule “MOtor State”
2018-03-28 20:34:13.093 [INFO ] [ipse.smarthome.model.script.Jalousie] - MOTOR_STATE changed -> FENSTER.state: ON MOTOR_STATE: ON
//rule “Motor ON”
2018-03-28 20:34:22.073 [INFO ] [ipse.smarthome.model.script.Jalousie] - FENSTER changed -> FENSTER.state: ON MOTOR_STATE: ON
2018-03-28 20:34:22.094 [INFO ] [ipse.smarthome.model.script.Jalousie] - FENSTER received command: ON
//rule “Motor State”
2018-03-28 20:34:27.709 [INFO ] [ipse.smarthome.model.script.Jalousie] - MOTOR_STATE changed -> FENSTER.state: ON MOTOR_STATE:
As you can see, the motor receices a second ON, but nothing happens. I believe, because the motor.state doesn’t change. I tried something like
when
Item MOTOR_STATE received command ON/OFF
but that doesn’t works too.
Any help?
Greetings Kaloschke