Edit API Node to update an entitiy attributes from different flows #2023
|
Hello, I am wanting to use the Edit API node to update an entitiy in HA. I would like to update the entity from multiple places in node red and am having some trouble with building the mustache payload in a node red function node. Example. Device 1 is a system fan. the entity is sensor.systemfan_1, simple enough, the status is a boolean T/F so I display OK or FAIL respectively, but I want to update an attribute "RPM" from another flow. I am using the function node in node red to send the data to the Edit API node, but I dont want to have to update the status "OK" just to update the attribute RPM if that makes sense? Function 1...msg.payload = { Function 2...msg.payload = { Any suggestions are welcome! Thanks in advance! |
Replies: 2 comments 2 replies
|
@brokenarrow03 yeah you absolutely do not need to touch the OK/FAIL state every time you just want to push RPM. The main thing tripping you up is probably the payload shape, and one detail about how attributes actually get written in Home Assistant. If you are wiring into the Sensor node (the blue Also in Function 2 you are writing the RPM value into Flow 1 (health/status)let attrs = flow.get('fan1_attrs') || { icon: 'mdi:fan' };
attrs.fanName = msg.payload.Fans[0].FanName;
flow.set('fan1_attrs', attrs);
msg.payload = {
state: msg.payload.Fans[0].Status.Health ? 'OK' : 'FAIL',
attributes: attrs
};
return msg;Flow 2 (RPM only, no state change)let attrs = flow.get('fan1_attrs') || { icon: 'mdi:fan' };
attrs.rpm = msg.payload.fan1rpm;
flow.set('fan1_attrs', attrs);
msg.payload = {
attributes: attrs
};
return msg;Wire both function nodes into the same Sensor node. Set Input Override to The reason for the On the HA side, the companion integration is built so state only changes when A few other small things worth checking
Hope that gets you unstuck. |
|
Hey just wanted to update you! This did work so thanks for the pointers. The only thing I had to change was the flow variable. I had to set it to a global variable, and due to this I changed the attrs variable to be a bit more descriptive so I woulndt end up with duplicate "fans" or something like that! Thanks again! |
@brokenarrow03 yeah you absolutely do not need to touch the OK/FAIL state every time you just want to push RPM. The main thing tripping you up is probably the payload shape, and one detail about how attributes actually get written in Home Assistant.
If you are wiring into the Sensor node (the blue
ha-sensornode that ownssensor.systemfan_1), the payload should sit directly onmsg.payload, not wrapped insidedata. Thedatawrapper is for the API node when you are sending a raw websocket command. Mixing those two up is a really common gotcha.Also in Function 2 you are writing the RPM value into
fanName. That should be its own attribute, something likerpm.Flow 1 (health/status)