Hi,
I am quite new to HA/Node-RED, so please forgive me if there is already a similar topic.
My setup:
-Home server box (essentially a custom built mini ITX PC) with HomeAssistant, Node-RED and MQTT servers all in seperate jails and with seperate IPs.
-Raspberry Pi (GPIO interface with my garage remote)
I have ‘hacked’ into my sliding garage door remote and wired it up such that it can be triggered via a python script on my Raspberry Pi. This script starts as a service on boot, and can successfully be called by pinging my Mosquitto server with “gate/open”, “gate/close”, “gate/stop” and “gate/lock”. This part of the system works brilliantly.
I am now in the process of setting up a HADashboard so that I can press a button on it, which would send the message to my Mosquitto server (via Node-RED). I have been searching and experimenting on this for a few days now but haven’t had any luck. So far, I’ve set up a dashboard with four buttons (one example below).
My problem is two-fold: Firstly, When setting up the entity, there are no ‘states’ to be read as the remote is effectively just a trigger. This means I am yet to produce a functioning piece of yaml to include in the configuration file.
Secondly, how can Node-RED read a button push if there is, once again, no state to be read?
I’ve been reading up about entities in the documentation and on forums - however the learning curve is rather steep and it’s difficult to find applicable examples. My attempts as producing an entity keep giving errors.
I do apologise if this is the wrong thread or has been answered before. But after a few days of research I’m yet to make any progress. Any help would be greatly appreciated!
NodeRED can use the MQTT node to listen to a broker. It doesn’t necessarily need to be listening for a state change in HA. So, if you can use the MQTT Publish service when it detects the button press, then NodeRED can be involved.
You can fire a script that publishes the topic you need when the button is tapped on the screen.
Based on your answer, does this mean that I don’t need to set up an entity in the configuration.yaml file? I just need to have node-RED listen to a button press? Or is the entity name still needed for Node-RED to know which button I have pressed?
Node-Red doesn’t rely on Home Assistant at all. You can pass MQTT data back and forth with Node-Red without HA being involved at all. Node-Red is a completely separate application that happens to have a way to connect to HA to run the automations.
So, this is my current understanding:
-I do not need to create an entry in configuration.yaml for my buttons (as they are simply triggers and not required to report or display an entities state)
-simply setting up the button on the dashboard (as per my code example in my original post) is sufficient on the HADashoard side of things
-the only step I need to take at this stage is get node-RED to identify when the button has been pressed (and trigger the appropriate MQTT call)
Is that correct?
Or would it simply be easier to trigger an MQTT call from HADashboard and skip Node-RED altogether?
I’ll have a go at putting this together later today or tomorrow and report back
Appreciate your help so far
You already started the Node-Red journey and will sooner than later migrate most of your tasks over to Node-Red … it usually is much easier and more flexible
And as @flamingm0e said … you don’t need HA at all
Yes good point - I’ve been playing around with node-RED and I have to say, I’m super impressed! It’s a brilliant little tool.
After thinking about it a bit more and fiddling around with a few things I’ve managed to get it working (sort of) and have also come to the realisation that I don’t necessarily need HA in this exact instance. However I’d like to still use HA as the control hub (I’ll be expanding on this as my home automation journey has only just begun!), which leads me to one last little issue I am facing.
I have created an ‘events: all’ node in node-RED, which feeds into a switch node. This then checks the entity_id of the pressed button and calls the appropriate MQTT pulish node. This works on the gate as expected which is a win!!!
The last piece of the puzzle for me now is the errored object that appears on the HADashboard. “entity not found: switch.gate_open” (x4 errors for each gate function). I have added the entity_id to my dashboard yaml to allow my switch node to determine which button has actually been pressed.
How can I add this ‘dummy’ entity to my configuration yaml file to resolve the error? I’ve been experimenting with finding an appropriate ‘platform’ for the switch but not luck so far. Or is there another way to pass a variable without specifying an entity_id?
Once solved, everything will be running perfectly!
Thank you all for your help so far, this is super exciting! (Not to mention that the wife has been annoyed our spare gate remote has been out of action for a few weeks!)
Thank you both! The input_boolean works exactly as I wanted. Problem solved.
I also swapped over to an EVENT:STATE node as well on m0e’s recommendation.