Hi all,
I am in the process of learning HA in the hope that I will be able to migrate over from a working OpenHAB setup. I have a new home solar system that I’ve found impossible to get working with OpenHAB that just works under HA.
I have been researching and been unable to get the following to work.
I have a 12-port button controller (Arduino Mega) that monitors buttons connected over cat5 cable using RJ45 connections. (It is purely an electrical connection, not data). Each port (or cable) supports up to 4 buttons.
The Mega is polling all inputs (though it’s IO pins) waiting for a button to be pressed then sends a MQTT message out on my network under the topic ‘buttons’.
It sends a unique message for each button. ie. 11-16, 11-17, 11-18, and so on (they actually correspond to the Mega I/O they are connected on, but that is arbitrary, is just has to be unique).
What I am trying to do is get HA to receive the MQTT message, then using an if/then or a lookup table of some kind, toggle a light on and off each time its corresponding button is pressed.
I have found a few code examples for automations.yaml, but none seem to work.
Any help would be greatly appreciated.
Incidentally I have about 6 homebrew Arduino and ESP8266 devices I use for switching various lights and devices on and off, including control and state of my roller door that use MQTT.
To migrate to HA I need to get a test system running proving I can replicate my currently OpenHAB setup.
Have you set up the MQTT integration in HA to connect to your existing broker?
Are you able to send and receive packets through the MQTT Config tool?
If those are working, all you should need for basic function is an automation with an MQTT Trigger. Optionally, you could create MQTT button entities then use those to trigger automations instead of directly using MQTT triggers.
If that isn’t working you’ll need to share the automation config or, even better, the debug trace of a failed run of the automation.
Hello ,
Troubleshooting MQTT? MQTT-Explorer can help you be successful!
If you have Apps available, try adding this App repository to your Apps list. GitHub - GollumDom/addon-repository · GitHub.
With this you can see that the broker sees and likely find the bug.
Also here is a project I used Python to talk to HA via MQTT, maybe some of the logic helps you in your code.
What you are trying should be easy enough to do.
I should have said that I have an MQTT integration set up. I have also been able to set up a text item and see the Button ID in HA.
My problem is setting up an automation to toggle the selected lights on and off.
The lights by the way are controlled by an ESP32 running Tasmota and the three relays in Tasmota appear as switches in HA.
Before you start messing around BACK UP ALL YOUR DEVICES
Since your Mega can send messages to an MQTT broker, I would suggest you look at MySensors. In the scenario I envision, the Mega would be configured to be an MQTT gateway with sensors. No radio required. The HA MySensors Integration has auto discovery … which obviates the need to decode the state of switches, lights, etc.
You’ll find the community members on the MySensors forum helpful.
On ESP devices I run Tasmota (which uses MQTT) and the HA Tasmota Integration which also has auto discovery.
As noted, for both, you would need the HA MQTT Integration installed, too.
If you added an nRF24 radio to your Mega and to your Arduinos, the Arduinos would easily integrate into HA.
example created with 9 clicks in visual editor (comments mine)
alias: _example
triggers:
- type: changed_states
device_id: fa970673d404d233a83483d9f724b5f6 # switch chosen from list
entity_id: f9dd9ac88b945df0d1412c026706762d # same switch chosen from list
domain: light
trigger: device
actions:
- action: light.toggle
metadata: {}
target:
entity_id: light.light_chosen_from_list
mode: single
I, too, recommend MQTT-Explorer. I use it to confirm that messages are being sent, but for Tasmota and MySensors, I’ve never found that the message itself was of much interest.
ESPHome also works well for ESP devices. It has the double-edged sword of auto updates. I found it a bit cumbersome to set up.