I have had my HA instance up and running for some time without issues, using nodered for automations. I have an Arduino micro programmed to read some analog sensors and pass the data to my pi4 usb via HA serial sensor (using Arduino JSON). Here is an example of a template sensor I made to handle the data (excerpt from my sersors.yaml):
- platform: serial
serial_port: /dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0
name: 'serial_sensor'
baudrate: 115200
- platform: template
sensors:
backup_battery:
friendly_name: 'Backup Battery'
value_template: >
{{ (100.0 * (state_attr('sensor.serial_sensor','battery')|default(9.0)|float*0.0145 - 9.0) / (13.1 - 9.0)) |int }}
unit_of_measurement: '%'
icon_template: >
{% set batt_prcnt = (100.0 * (state_attr('sensor.serial_sensor','battery')|default(9.0)|float*0.0145 - 9.0) / (13.1 - 9.0)) |int %}
{% set batt_prcnt = (batt_prcnt / 10) |int * 10 %}
{% if batt_prcnt >= 100 %}
mdi:battery
{% elif batt_prcnt > 0 %}
mdi:battery-{{ batt_prcnt }}
{% else %}
mdi:battery-alert
{% endif %}
I believe these templates are formatted to return integers (|int). In nodered, I was just using state change nodes to run automations (for example, if msg.payload<=30, battery is low so send a notification). Before upgrading to .112, these automations all worked perfectly. After upgrading, the automations started firing off randomly on their own. Looking in my recorder database, history, etc… also watching dev/states the battery % never dipped below 100, but the <=30 automation kept firing.
So clearly the 100
wasn’t being seen as 100
, and I start looking at type casts. After some experimenting, I determined that I had to delete the state nodes, and add trigger nodes with “numeric” state selected in the drop down box. Using trigger nodes with the default “str” state did not work. With the trigger node accurately reacting to numeric state, now all my automations work as they should. I didn’t change anything in my HA config (same as pasted above), just the node red ‘input’ nodes.
So problem solved, but I’m curious why this happened to begin with. Did something change with the way template sensors store data (like changing ints to strings internally), or something like that? …or maybe something changed in nodered that makes it more sensitive to improper variable declarations? With my problem solved this is purely academic, but I’m always interested in what makes the software I use tick, especially whenever it kicks back at me like that.