And a rule:
Assuming the the light is ON when both switches and ON or OFF
rule "Light"
when
Item Relay changed or
Item WallSwitch changed
then
if (Relay.state == WallSwitch.state) Light.postUpdate(ON)
else Light.postUpdate(OFF)
end
But we come back to this
You NEED to feedback the switch position to OH
Hi,
Yes I understand, its the reporting back that stumped me… But I have just had an idea that I will explore tomorrow (its late in NZ), what about connecting some type of CT coil to a GPIO to read back the ‘On or Off’ status to OH…
“Thats one way of doing it but due to restrictions of wiring and also if the system is down I want anyone else to be able to use the normal light switch.”
By having it worked like that the sonoff is doing it all, no openHAB MQTT or whatever is needed! You either switch the sonoff directly or using the other rewired switch you toggle a change.
I’m using a sonoff dual that way! While openHAB was down for maintenance the migth could be switched.
OK, So I have been working on this over the last few weeks, on and off (sorry excuse the pun!)
What I now have is a standalone Arduino with CT sensors that detect when there is a load on the lighting circuits of the Sonoff 4 channel. I have also managed to get the Arduino to send a MQTT message that the circuit is either ON or OFF. Either when Alexa is used to operate the Sonoff or the conventional switch is used. Its sends the message because it detects the load.
So I now have a way of feeding back the state to OH!
But this is where I am a little stuck and showing my OH and programming lack of knowledge. I am trying to figure out how I log the fact that the light is physically off in the OH system. So that if someone then uses Alexa to switch the light back on, the system checks the state and turns it on.
Not sure if you have seen this post updated? I have managed to figure out a way of feeding back the info to Openhab, I am just a bit stuck on what I need to do next…
The code and rule you showed, I dont understand how the MQTT message I am sending back is used to update the switch?
Hope you can help, I think I am getting close to making this work. I just dont have enough Openhab experience…yet.
I have an arduino that has a CT coil sensor connected to it. When this arduino and coil sense a voltage on the live wire to the light it sends an MQTT message to Mosquito saying the light is ON, and the same when its turned OFF.
Ah, this is the section of code in the arduino that sends the MQTT message-:
if ((Irms >= 1) && !sonoff4ch1_On) {
Serial.println("Light is ON");
client.publish("stat/sonoff4ch1/", "Kitchen light is ON");
sonoff4ch1_On = true; //Remember what state the light is
}
else if ((Irms <= 1) && sonoff4ch1_On)
{
Serial.println("Light is OFF");
client.publish("stat/sonoff4ch1","Kitchen light is OFF");
sonoff4ch1_On = false; //Remember what state the light is
But I dont understand how I make an item for openhab when its a message not an item?? Sorry I am very new to Openhab and not a programmer by trade…but very willing to learn.
Yes, its on a standalone Arduino Uno with an ethernet shield connected to the network. The CT coil is around the common wire to the light which senses the ON or OFF.
if ((Irms >= 1) && !sonoff4ch1_On) {
Serial.println("Light is ON");
client.publish("arduino/channel1","ON");
sonoff4ch1_On = true; //Remember what state the light is
}
else if ((Irms <= 1) && sonoff4ch1_On)
{
Serial.println("Light is OFF");
client.publish("arduino/channel1","OFF");
sonoff4ch1_On = false; //Remember what state the light is
Hi,
OK I have made those changes and they work ok it seems.
The Arduino sends the messages to Mosquito, which I can see in MQTTfx.
I can also see the state change event in the Openhab log viewer.
It appears to update the basic UI after a page refresh.
Alexa does not see the state change though, she is still seeing the relay state in the Sonoff.
If Openhab is seeing the change of state of the light being physically on or off, how does Alexa not see the same?
There must be more I need to do? Do I somehow have to disable the state updates from the Sonoff? or did changing the broker in the items file do this?