Would love some advice on the best way to achieve control/state for devices that aren’t natively MQTT like Arduino. I’ve deployed an Arduino board in my test environment which was too easy but I want to be able to now control the switch using MQTT. What is the best way to do that?
arduino:
port: /dev/ttyACM0
switch:
platform: arduino
pins:
11:
name: Fan Office
type: digital
12:
name: Light Desk
type: digital
default: on
negate: true
13:
name: Internal LED
type: digital
I know the answer will be obvious but brain is running in slo-mo at the moment. I’m assuming I could use a simple script to publish to a topic when a device changes state and vice versa?
For those that want to do the same, here is my automation code hiding inside a folder called ‘auto’ and included using the automation: !include_dir_merge_list auto method.
### Publish Wemo state via MQTT ###
- alias: Wemo MQTT on
trigger:
platform: state
entity_id: switch.wemo_switch
state: 'on'
action:
service: mqtt.publish
data:
topic: 'mqtt/switch/wemo'
payload: 'on'
- alias: Wemo MQTT off
trigger:
platform: state
entity_id: switch.wemo_switch
state: 'off'
action:
service: mqtt.publish
data:
topic: 'mqtt/switch/wemo'
payload: 'off'
I now have a light icon on MQTT Dash that changes state when the Wemo does. Now to get the icon to turn it on and off.
OK, trying to get control but not working. Anyone see a glitch?
## Wemo control via MQTT ##
- alias: Control Wemo via MQTT
trigger:
platform: mqtt
topic: mqtt/switch/wemo/control
# Optional
payload: 'on'
action:
service: switch.turn_on
data:
entity_id: switch.wemo_switch
I’m publishing the payload ‘on’ to mqtt/switch/wemo/control via MQTT.fx and the switch is not turning on. Also, when I add this yaml file to the ‘auto’ folder, the previous automation to track the status of the wemo also stops working. Can see anything in the log.
I’m trying to achieve something similar by using a physical switch I made connected to the gpio pin on my pi. When the switch is pressed, it goes login HIGH (5V). I can’t for the life of me get it to work with the physical switch.
I’ve tried rpi_gpio with both binary_sensor and switch methods to no avail. This is the code I’ve tried for each:
Have you got the GPIO working on its own? According to the Wiki, the GPIO pin 21 is a digital out, 20 is digital in. Have not played with Pi GPIO at all but I’d get that working first and then concentrate on MQTT second.
I’m pretty much just trying to get the GPIO working on its own at the moment. I’m pretty confident that the MQTT stuff is working properly so not even focusing on that. I’ll check out the DIGI in/out of the pins though. Cheers.