I started using GPIO’s to get switches connected to OH. It took me a bit but it works. I am now in the process on implementing MQTT, so appears I’m doing the reverse to you in that respect. Anyway, do you know how to setup a toggle function in OH using two GPIO pins and one switch item?
For clarification I have an RF remote which have separate On and Off buttons. At the moment I have an On and Off switch setup in OH and using .rules to toggle each switch for 500ms. I am finding it a pain to tell my google home commands. The switches are setup for example, Lounge_On and Lounge_Off. So if I want to tell G’home to turn on the lounge lamp I have to say “turn lounge on on” and to turn off "turn lounge off on. It would be nice if I could switch it the usual way.
My thought train was along the lines of MQTT where you have the line
I have never tried that myself, but I believe it is possible to attach two outgoing and two incoming MQTT commands to a channel.
So as ON command you could actually send the ON command for the One and the OFF command for the other
There is no specific binding for analog values afaik.
But what you can do is read the value of /sys/bus/iio/devices/iio:device0/in_voltage_raw and either MQTT that to openhab OR use the REST API to put it in openhab.
This is simple to do with Python.
If you dont know how, have a look at how the DS18B20 or DHTx transfers their values with a python program, it basically comes down to reading the file, parsing it to get just the one value you need and then use MQTT or REST.
REST API uses: requests.put('http://192.168.xxx.yyy:8080/rest/items/<YOUR ITEM>/state',value) .
What if I want to control the LED with a script? Is this possible while using this binding? I want to write a script that turns off the normally on LED when the state of a thing changes.
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
26
Hi
Would you happen to know if this process is purely for Raspberry Pi, or can I try it on any Linux based SBC?
@MDAR I don’t know about support from the GPIO binding, but you could maybe use my MQTTany. Currently the GPIO module only supports RPi but can easily be modified to support other boards if there are Python 3 libraries available to control their GPIOs.
Let me know if you are interested and if you already know of any Python libraries.
1 Like
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
28
Thanks Michael.
I have limited knowledge of anything outside of GUI things.
So python is outside of my skill set.
No I mean I would make the changes. Looks like there is a library. I’ll get to this next, I’m just working on a module for DS18x20 sensors right now. Keep an eye on the github for the odroid support getting added.
I don’t know Python that well either, but when you can see an example of how simply it is, it makes life easier
So if you want to control the LED via a script, create a simple python script to turn off the LED. Then use the exec binding to call the script in a rule when the state of something changes.
Say you had the LED controlled via GPIO pin 25. First I’d assume (hope) you would be controlling that LED light via a transistor (like a Darlington TIP120 and 220ohm resistor to protect the pin) After installing python (plenty of articles on how to) then you’d create a script that would look something like this:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(25,GPIO.OUT)
GPIO.output(25,False)
GPIO.cleanup()
Save to for example: /usr/local/share/gpio25.py
To test execution, simply type this from the command prompt:
python gpio25.py
Your LED should turn off.
If you want to turn on, you can simply send ‘True’ to the GPIO.output command rather than ‘False’ in the script above.