Hi there,
I´m again struggling with my "Home Assistant" integration in Node Red which actually provides global variables for each entity of the system. For what reason ever, all values are provided formated as a string which makes it really hard to use when you need to operate with numeric dates (temperature, humidity etc.). Therefore, I´m looking for a way to directly get the numeric state of certain entities within a function node to operate with them further. Anybody that has done that before and maybe give an example how to achieve this?
Can you show the actual data?
@zenofmud - You mean of the global variables from Home Assistant?
Of the data going into the function node. Make sure to set the debug node to display the complete msg object.
It would also be helpful to see the function node.
Alright, maybe I should be more clear of the scenario I want to cover:
- Motion sensor A detects motion (events state node)
- Based on this I want to create a function node that checks the illumination entity of sensor B to decide whether to switch on the light or not.
So for this I want to know how to read the state of certain entities from within a function node.
I'm gong to assume you have someway that you are durrently getting the information from sensor B. What I would do it store the value received from sensor B in a flow variable. Then when sensor A generates a msg, you could check the state of the flow variable (you could use a switch
node) and determine if you should to turn on the light or not.
Yes I know I could use a certain state node, but if you are operating with multiple sensors u need a lot of variables which I think is quite some overhead. So is there really no way to read values from an entity within a function node ?!
What version of NR are you using?
As of release 1.3.0 the function
node allows you to load external modules. So if you have a node module that will read the senson you could investigate that.
You can convert the values with a change node
I am using a similar situation (although I dont use home assistant, just everything in NR).
The ambient light sensor continuously updates a global variable and whenever the motion sensor is triggered, i use a switch node that checks the variable and either blocks or passes the message
Thanks @bakman2 - Still this again is a solution that makes use of global variables, which I actually would like to avoid as I probably would need to constantly update about 20 global variables to use in different flows. But maybe that´s just the way it has to be once there is no possibility to directly read a value of an entity from within a function node.
If you receive messages from multiple sensors at the same time (or grouped by number of messages or in a certain timeframe) you can do it, if not, you will need to keep track of the values as messages pass through the flow from a to z.
Note that node-red is not a “state” tracker, that is exactly what home assistant does.
Yeah, I guess u r right - it should actually be Home Assistant storing the data properly, but fails miserably doing so. I guess I have to get back using global/ flow variables for keeping track of entities states myself then
So what version of the Home Assistant Webhooks add-in are you using ?
Are you using a fullcopy of NR - or the copy from HACS?
Have you checked on the Home Assistant forum re this ?
If you look at the Ultimate Boolean node i think it will allow you to do what you want i.e. line up multiple entities that are outputting states and you can then feed them into the Ultimate Boolean node
Have a look here
Craig
This Blog post might help you also
Craig
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.