Help with setup/rules in openHab for Momentary buttons

  • Platform information:
    • Hardware: RaspberryPi3+
    • OS: Raspbian Latest
    • openHAB version: 2.4.0

Hi guys, im trying to get working my light controller, the way it works it it creates a number value based on the ButtonID and deviceID

So for Example if deviceID is 20,
and ButtonID is 41,
this would create the string 20-41
The buttons i am using a Momentry so im guessing i would need to setup in rules to check the status of the device(light in OpenHab) and then toggle the output to the other. and then have openHab change its status according

My Light controller only publishes so it doesn’t care for a reply of the status of the light it will just send the same String each time the button is pressed.

My Arduino code for generating and publishing to MQTT is

String messageString = String(panelId) + "-" + String(buttonArray[buttonId]);
          messageString.toCharArray(messageBuffer, messageString.length()+1);
        
          //String topicString = "device/" + String(panelId) + "/button";
          String topicString = "buttons";
          topicString.toCharArray(topicBuffer, topicString.length()+1);
  
          //client.publish(topicBuffer, messageBuffer);
        
          client.publish("buttons", messageBuffer);

This publishes to the topic of buttons with a different String depending on the button that is pressed.

how could i get OpenHab to read this String and use that to toggle the channel on or off.

Cheers

Hi

I’m not entirely sure what you’re trying to achieve, but I suspect you want to split the string and do something with it,

Do these topics help you?

Good Luck,

Stuart

Hi @MDAR

im making a light switch controller, but its stateless, so on a button push it will output over MQTT a string like 20-41

from there im trying to get openHab to pick this up by monitoring the topic and change an output. or in my case that will be a relay on a different arduino.

hopefully that makes things a little easier to understand

Do you need help with the MQTT side of things or the rules ?

More so the rules, currently when i push the button, it publishes to the topic of buttons with a string of 20-41

so that parts is working. im stuck with the rules in openhab to see this String and act according.

id like to be able to press the button on the wall and have it turn a light on. but then also be able to use the App and turn the light off.

Okay, that’s good progress then.

So as long as you have a String Item in openHAB that changes when it receives an update from your MQTT broker, then the topics I linked to should get you much closer.

Unless you are trying to filter parts of that message and do different things.

In which case this topic might help you?

I’m really a Velbus guy, so anything else is pure guesswork and a great deal of trial and error.
(Until some kind soul shines a light on a solution)

i guess the only filtering that would need to be done is on different buttons 20-41 is button 41 on panel 20.
so id assume i could setup a second rule to monitor 20-42 and all the other buttons using a Mega i can get 48 buttons per board.

Have a good read of those topics I’ve linked to.

I’m certain you’ll find something in there to help you.

Very generous people have spent a lot of time fine tuning the issues in each one.