i have myself a light switch controller, the same one that john built in episode #25, ive spent the past 2 day trying to get it to work, but i just cant seam to wrap my head around how to get it to work with MQTT. from my understanding (correct me if im wrong.
This part that publishes to MQTT would publish to buttons/20-41, if the panel id was 20 and button 41? or have i just completely confused myself in this
i think im battling a few issues here, the other being the actual connection to Mosquitto from openhab.
any help is much appreciated
EDIT, i have got openHab and the light-switch controller (ethermega) now talking to mosquitto, just not in the same topic by the looks of things
Edit 2, @jon Might actually have the most help here, im sure im sitting right on the answer, more then likely ive just set up my broker incorrectly. or rules
Hi @Bedrock.
The double forward slashes turn that line of code into comments, which is ignored by the compiler/computer. Most likely used at some stage by @jon but no longer needed.
Hey @Bedrock.
Yep, you’re correct! Topic of buttons with string of 20-41.
You need openHAB to subscribe, not publish to buttons, in order to read in what your Arduino has published.
I was never successful in using openHAB’s rules engine. The lack of complete working GUI and the inability to modify it’s console database directly, I moved from openHAB to NodeRed. So I don’t think I can help you much further than the Arduino side of things.
I can’t help you with any openHAB questions. I’ve forgotten how any of it works. I’ve had much better success with NodeRed for the last few years.
NodeRed has native support for MQTT, once configured/connected as a client.
All of my devices either subscribe or publish to a MQTT channel.
Example - Sonoff with touch button to control lamp:
-Sonoff subscribes to “device/lamps/1”
-NodeRed subscribes to “nodered/lamps/1”
NodeRed stores state of lamp. Either on or off.
Button is pressed on sonoff, it publishes to “nodered/lamps/1”
NodeRed sees that message.
NodeRed checks previous state of lamp, eg: off. Toggles the state to on.
NodeRed publishes to “device/lamps/1” with a message of ON.
Sonoff sees that message of ON, turns lamp on.
Function “Lamp 1” code:
// Determine previous state, or if never set: set to false
var state = (flow.get('lamp1_state') == true);
// Toggle state
if (state)
{
// Store state for next time
flow.set('lamp1_state', false);
// Set our OFF message
msg.payload = "0";
}
else
{
// Store state for next time
flow.set('lamp1_state', true);
// Set our ON message
msg.payload = "1";
}
// Send message
return msg;
Hey @chris, thanks for your help, finally got my lights switches working, well the control side of that at least. im now stuck on the arduino side for toggling the relays. have you played around with Relay8’s i just cant seam to get mine to work.
I can get 2 working if i use the example code @jon has on the Superhouse Github, but i cant get the second 2 working. any ideas?