Openhab2 mqtt items and sitemaps

  • Platform information:
    • Hardware: CPUArchitecture/RAM/storage
    • OS: what OS is used and which version
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version:
  • Issue of the topic: please be detailed explaining your issue
  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

i want to control 8 channel relay by creating 8 switches with openhab please help me with the items and sitemaps creation or the code for items and sitemaps. iam using mqtt binding also.so, please suggest the coding with mqtt included.

please anybody suggest me the solution.

We need a bit more info from you, please.
at least

  • do you have MQTT up and running (Server, Clients, …) - or do you just start
  • Which 9 channel relay is it, you’re using

normally it would just be like this in your .items configuration:

Switch Action_Actionrelay1 "My Relay 01" { mqtt=">[mqttoh2broker:cmnd/sonoffRF1/RfKey1:command:ON:default]",autoupdate="false" }

In that case, it’s a copy from my Sonoff RF Bridge 433, which triggers the Brigde to turn “Rfkey1” on “ON”.

What you’ll need to to:

  1. fill in your Broker (instead mqttoh2broker in my case)
  2. fill in your MQTT topic (instead cmnd/sonoffRF1/RfKey1)
  3. the type (in my case “command” could stay also in your case - but that’s just a guess right now)
  4. the transformer (in my case “default”, could also stay)

Please see the docs for more reference:

(if somethings unclear in the docs, please say so, the docs can be updated anytime)

hai thank u for responding.

my mqtt is running fine and iam using a 8 channel normal relay so please tell me how to create items and sitemaps.

i connected all 8 pins so i want to control all 8 relay connections with 8 switches please provide some solution.

thank u,

Sorry, still the same answer, I cannot guess, what MQTT-Topics your relay uses und what commands it expects…
So, if you’re unsure what to do in OH2, please post the MQTT-commands, you’re sending to the relay to turn it ON or OFF. From there we can go further.

i don’t know the mqtt commands for items and sitemaps to create a switch.

i want to create ON and OFF for all the 8 ports of the relay to control 8 lights from openhab.

i have connected the relay IN ports with jumper wires to raspberry pi 3 to different gpio pins.

so, please tell me how to create items and sitemap for the relay.

actually i installed MQTT broker and client and i tested the demo

now i want to create the switches for the relay.

I’m sorry, but this is confusing. I don’t understand your setup and I guess so do you… :wink:

ok, you could have

  1. an external relay, which can be triggered by MQTT (please read carefully, what MQTT is here: http://mqtt.org/faq)
  2. or you have a hardwired relay on the raspberryPi you’re running openhab on

If 1. => then the MQTT-binding comes into place, with this, openHAB2 is able to send MQTT-Messages to the configured broker. If your MQTT-driven relay is also connected to that same broker and you’re sending the correct MQTT-Messages (Topics and values), then your relay opens or closes on that commands.

If 2. => then you don’t need MQTT at all, but you have to find a way, how OH2 can control your GPIOs on that Raspberry Pi. There’s a binding for this, but I don’t use it: http://docs.openhab.org/addons/bindings/gpio1/readme.html

this is the item to control a 1 channel relay.

Switch NormallyClosedRelay “Normally Closed Relay” { gpio=“pin:2 activelow:yes initialValue:high” }

and how to write sitemap code please help me.

and also if i want control 8 channel relay how to create the items and sitemaps with the above mentioned type code to work the switches.

Yeah this is very confusing and such a big ask “can you do all this for me but I’m not telling you much”

Personally just because I have an RPi running with a single relay on it I’ll say how mine is setup but it’s not the only way as @binderth has shown.

I’ve enabled MQTT publishing on my evert queue so that all items post command changes rather than creating specific items that post unique MQTT messages. Works for me because I control my clients but clearly with Sonoff or others you might not have the choice.

On my RPi client I’ve just adapted a python script to subscribe to MQTT message items it’s interested in and then react appropriately and deal with all the GPIO stuff.

1 Like

OK, now. I think, you won’t need MQTT for this at all. So please feel free to read the GPIO-Documentation I gave you earlier. There you can see on how to use the other PINs on your Pi (I guess simply by changing the PIN-number:

Switch NormallyClosedRelayPin2 “Normally Closed Relay Pin2” { gpio=“pin:2 activelow:yes initialValue:high” }
Switch NormallyClosedRelayPin3 “Normally Closed Relay Pin3” { gpio=“pin:3 activelow:yes initialValue:high” }

=> please also read the Item-documentation on how Items are configured and to what purpose: http://docs.openhab.org/configuration/items.html

So, how to get items into a sitemap?
=> please read the sitemap-documenation on how Sitemaps are created on how items work within these: http://docs.openhab.org/configuration/sitemaps.html

To stick to my example above, it could be just like that:

sitemap demo label="My home automation" {
    Frame label="Muralis Relay" {
        Switch item=NormallyClosedRelayPin2 
        Switch item=NormallyClosedRelayPin3
    }
}

If you’re still confused, please start reading the whole openHAB2 documentation here:
http://docs.openhab.org/introduction.html

hai,

i have tried the way u said and triggers are not working.
switches are not triggering the relay and relay is not reacting.

tell me what have to do??

Murali,

I’m sorry to say it’s not the way it works. openHAB doesn’t work that way - and this forum doesn’t.
I still have the feeling you didn’t read anything on openHAB at all and want us to solve some problems, you can’t describe for yourself.

My advice:

  1. make sure, your setup works without openHAB (meaning, you know exactly how to address your relays without any kind of automation.)
  2. make sure, you understand what openHAB is and what it stands for (again, read the intro I gave you above - thoroughly and comprehensively)
  3. then start with some simple tasks like understanding what items are and how to link them to a sitemap, if that’s your goal (see, we don’t even know, what you would like to achieve with openHAB!)
  4. if you know in theory how openHAB works in principle - and you know what your goal is with your relay, then
  5. think on how to combine openHAB (which is nothing more than an means to automate tasks, which are already present!) with your goal and how openHAB helps with automating this
  6. if you find major obstacles on the way, you’re more than welcome to discuss those with us in the forum, but
    6.1 we need a better description than you gave us already
    6.2 we need your configuration / steps towards your goal, which lead to nowhere
    6.3 and we need to know your goal, then we can help you
    6.4 and finally we need to be sure, you read the documentation, so we can make it better, if that is where you didn’t find answers in the first place

Sorry, if that’s not, what you’re looking for, but we can’t just throw in some magic, that works for you withour those steps…

First question woul be, if the code for the 1-channel relay is working in your setup or if this was just a copy and past of some tutorial?

Can you switch a channel of your relay without openhab? How can you do this? Give us the correct command and the whole way you do this.

After that, we can tell you, how you can implement this to openhab. And after that, we can tell you, how you can create a sitemap with this.

Is your openhab already running and working with other items/bindings or do you start from scratch with openhab on a fresh installation and this 8-channel-relay will be the first thing you want to control?

hai,

i did the 1 channel relay with this below code without openhab

ON:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)
GPIO.output(4,1)

OFF:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(4, GPIO.OUT)
GPIO.output(4,0)
GPIO.cleanup(4)
GPIO.setwarnings(False)

and with openhab i cant trigger the switch for the relay.

Murali,

thanks for posting this. Still, you lost us. Please be more specific in what you do and what you want to achieve.
for example, from the code you posted, I assume, this is a python-script. But you don’t mention either the script nor the PINs you’re using… It’s just one PIN (4)
So, I assume you did the following:

  1. connected one channel of the relay on GPIO PIN 4
  2. installed python and the GPIO library (raspberry-gpio-python ?)
  3. you tried it out and it works

so, now we know (or assume?) what you did and I also assume (you didn’t tell us…), you would like to use more than that one PIN (GPIO 4). So we’re lacking more information:

  • Which Raspberry Pi model you’re using (there are differences in the GPIO-PINs per model)
  • on what PINs your “8-channel relay” is attached to

What I ask now comes as no surprise… :wink:

  1. please provide more insight on your Hardware Settings and how you manage to Control your 8-channel relay without OH2
  2. please provide your steps within openHAB2 and most importantly,
  3. please post logfile entries form/var/log/openhab2/openhab.log and /var/log/openhab2/events.log

From the distance, there are two ways to use your switches in a sitemap and connect them via OH2 with your GPIO-Pins

  1. using the “exec-binding” and calling you python-scripts [http://docs.openhab.org/addons/bindings/exec/readme.html]
  2. using the “gpio-binding” and using openHAB for this http://docs.openhab.org/addons/bindings/gpio1/readme.html[]

for 1) you have to either provide a script for each PIN and each state - or using parameters for starting the script (which your script must parse and can then do the rest for you)
for 2) you have to follow thoroughly the documentation I already gave you multiple times (GPIO binding!)

Judging from your questions in this thread and your other posts in other threads in this forum, I would go with 2. But PLEASE read the documentation, follow the steps in it and tell us, if you get stuck with more information than you provided us until now.

1 Like

hai thomas,

how are you??

i successfully completed the 8 channel relay testing with openhab.
now i want to create the items into categories like separating the living room items to living room like these…
so please tell me how can i separate them into different categories.