Update custom entity from Node-Red

I’m not sure if I’m going about this the best way. Ideally, I want to display a round icon that is either red, yellow, or green along with a text. That is the important part. I also have some other data I’m unsure if I want to track as a sensor or have on hand at the moment (so more sensors/atrributes vs more input text).

Right now I have this template in HA and I cannot figure out how to send any data to it.

template:
  - sensor:
      - name: "Window Status"
        state: "{{ state_attr('sensor.window_status_data', 'status') }}"
        attributes:
          reason: "{{ state_attr('sensor.window_status_data', 'reason') }}"
          indoor_dew_point: "{{ state_attr('sensor.window_status_data', 'indoorDewPoint') }}"
          outdoor_dew_point: "{{ state_attr('sensor.window_status_data', 'outdoorDewPoint') }}"
          dew_point_difference: "{{ state_attr('sensor.window_status_data', 'dewPointDifference') }}"
          humidity_difference_limit: "{{ state_attr('sensor.window_status_data', 'humidityDifferenceLimit') }}"
        icon: >-
          {% if is_state_attr('sensor.window_status_data', 'status', 'unsafe') %}
            mdi:close-circle
          {% elif is_state_attr('sensor.window_status_data', 'status', 'caution') %}
            mdi:alert-circle
          {% elif is_state_attr('sensor.window_status_data', 'status', 'safe') %}
            mdi:check-circle
          {% else %}
            mdi:help-circle
          {% endif %}

Now nodered outputs this, and I can modify it to whatever, of course…

{"status":"unsafe","reason":"Too hot outside (73°F).","indoorDewPoint":"56.04","outdoorDewPoint":"50.84","dewPointDifference":"5.20","humidityDifferenceLimit":"2.60"}

And yes, my integrations are working properly, I’m sure there are minor updates, but I’m fully up to date on both ends as of two weeks ago. I’m just stumped since call service is now actions, and the way things are done feels a bit backwards to me. Basically I can’t find any combination of device type or method that allows a simple update of multiple parameters (unless it’s a switch, sensor, or basic text box). And my searches yield nothing, so that tells me it is likely easier than making a post here lol.

I’m also open to trying it a different way; everything in NR is solid up to the point of sending the data to HA. Thanks!

Everything in your template references that entity. Does that entity exist? Or do you want to create sensor.window_status_data in NR with the attributes in your template?

It is present according to HA states:

reason: null
indoor_dew_point: null
outdoor_dew_point: null
dew_point_difference: null
humidity_difference_limit: null
icon: mdi:help-circle
friendly_name: Window Status

As I stated, my roadblock is pushing the data to HA. I initially tried creating the sensor in NR but this one is more than one parameter. In either scenario I can’t figure out how to get the data to HA. I tried the action node but it is giving me next to no options, maybe because it is a custom entity? I don’t have it anymore, but I have done this in the past and it was very easy, this was back when it was call-service and the action was set or update. I believe I was simply passing a formatted array to the device and HA was formatting it based on my template - years ago, could be wrong haha.

I’m not aware of a service to update a sensor in HA. Action is just the domain and service. So what used to be

"domain": "light",
"service": "turn_on"

Is now

"action": "light.turn_on"

You can create this sensor inside NR. See this post for how.

I’ve done the NR to HA direct create method for many other things. I think I’ll need to split up the output to multiple entities and bring it together with a template. I’ve also considered sending the required data to HA and coding the logic in a template. I need to sleep on this - yet again haha. Thanks.

If you use the HA WebSocket ‘Sensor’ node in Node-RED to create a new sensor “Window Status” then this will be created in Home Assistant and you can update the state and attribute values from Node-RED.

If you are starting with an object in Node-RED (in msg.payload for example)

{
   "status":"unsafe",
   "reason":"Too hot outside (73°F).",
   "indoorDewPoint":"56.04",
   "outdoorDewPoint":"50.84",
   "dewPointDifference":"5.20",
   "humidityDifferenceLimit":"2.60"
}

and you want to pass all of this to HA, then you can

  • place payload.status into the sensor status
  • place each other value into an attribute as required, eg ‘reason’ attribute as payload.reason

As you also wish to change the sensor icon, then you can use the Update Config node. This special node permits changing the sensor (entity) name or icon from the Node-RED flow. This can be done, directly from the window status value, using JSONata code to generate the correct ‘mdi:icon’ required, which can then be passed in msg.payload.icon to the update config node.

This easily passes all parameters and manages the icon in just two nodes.

[{"id":"9aa093acd1bfd7c5","type":"ha-sensor","z":"60bdd784a3412b28","name":"Window Status","entityConfig":"7a3f9336e991c749","version":0,"state":"payload.status","stateType":"msg","attributes":[{"property":"reason","value":"payload.reason","valueType":"msg"},{"property":"indoor_dew_point","value":"payload.indoorDewPoint","valueType":"msg"},{"property":"outdoor_dew_point","value":"payload.outdoorDewPoint","valueType":"msg"},{"property":"dew_point_difference","value":"payload.dewPointDifference","valueType":"msg"},{"property":"humidity_difference_limit","value":"payload.humidityDifferenceLimit","valueType":"msg"}],"inputOverride":"allow","outputProperties":[{"property":"payload","propertyType":"msg","value":"(\t    $s:=payload.status;\t    $icon:=$s=\"unsafe\" ? \"mdi:close-circle\" : $s=\"caution\" ? \"mdi:alert-circle\" : $s=\"safe\" ? \"mdi:check-circle\" : \"mdi:help-circle\";\t    {\"icon\": $icon}\t)","valueType":"jsonata"}],"x":520,"y":860,"wires":[["1c63809dcd6144ad"]],"server":""},{"id":"c00972406d25f2d3","type":"inject","z":"60bdd784a3412b28","name":"Test","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{    \"status\":\"unsafe\",    \"reason\":\"Too hot outside (73°F).\",    \"indoorDewPoint\":\"56.04\",    \"outdoorDewPoint\":\"50.84\",    \"dewPointDifference\":\"5.20\",    \"humidityDifferenceLimit\":\"2.60\" }","payloadType":"json","x":290,"y":860,"wires":[["9aa093acd1bfd7c5"]]},{"id":"1c63809dcd6144ad","type":"ha-update-config","z":"60bdd784a3412b28","name":"Change Window Status Icon","server":"","entityConfig":"7a3f9336e991c749","version":0,"outputProperties":[],"x":800,"y":860,"wires":[[]]},{"id":"7a3f9336e991c749","type":"ha-entity-config","server":"","deviceConfig":"","name":"SC Window Status","version":6,"entityType":"sensor","haConfig":[{"property":"name","value":"window status"},{"property":"icon","value":"mdi:help-circle"},{"property":"entity_picture","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false}]

A very simple way of creating a new sensor, updating the entity state, and passing lots of data in attributes, as well as changing the sensor icon.