TL;DR:
- Edit the node
- Click on Deprecated Settings to expose the State Type field
- Change this to “string” [from “number” or from “boolean”]
- Click on Deprecated Settings to hide the field again
- Save the node: Redeploy when done
Notes:
- IF the node has an output property that is set to
entity state
- Set the new field end option to match the original State Type (number → “as number”; boolean → “as Home Assistant boolean”)
- IF the node has If State conditions that test the entity state and
IF the original State Type was “boolean”
- Then any tests for
true or false will need to change to match the Home Assistant entity-state string [ eg test for “open” / “close” or “on” / “off” or “home” / “away” ]
- IF the node has an output property like
msg.data that is set to entity
- Then any use of
msg.data.state in following nodes may need to change also
The message is a warning only, and no immediate action is required.
References: https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/issues.html#state-type-deprecation
For those, like me, who had no idea what this Breaking Change was about…
This applies to the HA WebSocket nodes from version 0.79 onwards.
It applies only to the ‘state’ nodes:
- Current state
- Events: state
- Trigger: state
- Poll: state
The UI option for ‘State type’ is being removed for the node. The option will go entirely at some point before the future release of version 1.0.
What changes when I update to version 0.79+?
Nothing much. The node will have the same settings and will work exactly the same.
- The UI editor field
State type has been moved, and can only be accessed by clicking on the message [Deprecated Settings (click to expand/collapse)] at the bottom.
- There will be an error message for some of these nodes, depending on your current settings
What do I have to do now?
Nothing. Unless you want to remove the error messages, in which case you will have to change the State type setting in the node affected.
At some point you will have to make a change to the node settings, before this option goes completely.
What is changing?
Home Assistant keeps all entity state values as strings. The ‘state nodes’ currently have the option to change the state using the ‘State type’. The options are
- string (no change is made to the state value)
- number (a string containing a number is turned into a number)
- boolean (a string is turned into a boolean
true/false)
The node:
- looks up the entity / entities specified and read the HA state object for each
- converts the entity ‘state’ value from string to number / boolean if required
- performs the conditional tests - using the converted state value
- builds any output properties - using the converted state value
From point 2 onwards, the node only knows the state value in the required type, and any condition test, output property, or use of JSONata $entity().state will return a string, number, or boolean value
In the new arrangement, step 2 will no longer take place. This means that the node will only hold the entity state as a string throughout.
In summary
State type (changing the node-view of state value) from string to a number or boolean will not be possible. State value will remain as a string.
A new feature is added, which performs optional state-casting in the Output properties.
How can I remove the error message and get the node ready for the new way of working?
- If the State type is “string” then no state-value conversion is done. This is the intended way forwards, so changing State type from “number” / “boolean” to “string” will stop the error message. [you may have to wait / reboot Node-RED to clear the error message]
- If the State type is “number” or “boolean” then all you have to do is change it to “string”, but additional changes may be required.
What does changing State type “number” to “string” do?
This leaves the entity state value as a string inside the node.
There is no impact on any conditional tests you may already have.
Any conditional test using > < = <= >= will still expect a number literal to test against. The node continues to perform the conditional test between the entity state (as a string) and the conditional test value (as a number).
Output properties of ‘entity state’ and any use of JSONata $entity().state will need to change.
If you are using entity state as an output property - eg to msg.payload - then there is now a new option for casting the state value, just for this entity state output.
Set the type to ‘number’ and the state value will be cast from string to a number.
If you are using $entity().state anywhere in JSONata in the node, then this will now return a string and not a number. The JSONata code expression will need to change to either work with the string, or to use $number() function to perform the change. [JSONata $number() function will only accept entirely numeric strings].
What does changing the State type “boolean” to “string” do?
This leaves the entity state value as a string inside the node, and does not convert the state to boolean true / false
Conditional tests will have to change to accommodate this.
If you have a conditional test on a switch, which returns “on” or “off”, then the state value will remain as a string. Tests will need to compare the state with “on” or “off” and not true or false.
What is the different between “boolean” and “Home assistant boolean”?
Home Assistant does not recognise the concept of boolean true and false. All state values in HA are strings, and although these can represent numbers and boolean values, they are still a string.
HA boolean sensors will use a string pair to represent true/false, such as
- “on” -“off” (lights and switches, motion sensors)
- “home”-“away” (people in zones)
- “yes”-“no”
- “open”-“close”
The ‘State type’ option being removed permitted the conversion of recognised Home Assistant strings to boolean true or false using a lookup list. This lookup is defined in the Home Assistant Server configuration node.
In the Node-RED editor debug window, Home Assistant tab, Server, you will find field State boolean and a string list y|yes|true|on|home|open.
If the entity state contains a string that exactly matches “y” or “yes” or “true” or “on” or “home” or “open”, then the state value is cast to boolean true, otherwise to false
This option remains for the Output property, as option “Home Assistant boolean”
The option ‘boolean’ is new, and performs a casting of the entity state value to boolean using a more traditional procedure.
If the state string holds “True”, then this will be converted to lowercase first, then tested for an exact match to “true”, returning boolean true. The same for “False”.
If the state string holds a number, then this will be converted to a number, with 0 returning false and everything else returning true.
Other points to watch out for
The state value-casting does not take place where the output is “string”, either for the old State type or for the new output option.
If the existing State type is currently set to “number” and successfully converts the state value string to a number, using output type “string” in the output properties does not turn the node held state value back to a string - it will still remain as a number.
I hope that this is a correct assessment (apologies to Kermit et al if it is not) and I hope that it helps someone in the future.
Enjoy!