I’m trying to read a bunch of sensors via the get entities nodes in nodeRED. THis is working fine problem is trying to parse them out into separate messages for processing.
I want to read light , motion , temperature data and do some logic for controlling other devices.
I know I need to use a function, key is i need help getting the syntax to break the array of data into individual (fixed) messages like temp, lx, motion, state.
I’m new myself so forgive me if I make any mistakes.
I’m using a sequence of an inject, function and debug nodes to get the states of all my entities. Inside the function node I have this code:
var states = global.get('homeassistant').homeAssistant.states;
msg.payload=states;
return msg;
After that, from the debug messages tab I search for the entity I want to control and then use the “copy path” and “copy value” buttons to get what I want and store it in a variable. For example:
var Floor_Lamp_bright = states['light.floor_lamp'].attributes.brightness >= 128;
After that it’s a matter of if-else if statements.
Hey lex it seem a bit long winded, since current state outputed to a debug node set to full msg will give you that without having to grab all the state your doing in the var state
No
Current state node will get you the state of one entity only, as far as I understand it. This way you are getting the current states of all entities and you can combine them in your if statements as you see fit.
For example, if it’s between midnight and dawn and you’re home and all the lights are off and the floor lamp is on and below 40% brightness or off and there’s movement in a certain pir sensor, set the brightness at 40% and at red color (that is actually my nightlight sequence for the times I get up in the middle of the night and want a glass of water or want to go to the bathroom).