State type is deprecated and will be removed in version 1.0

What does this mean and how do I solve it? I have many of these errors:
State type is deprecated and will be removed in version 1.0

Deprecated Settings (click to expand/collapse)
The following settings are deprecated and may be removed in future versions. It is recommended to update your configuration to avoid potential issues.

Warning: The ‘State Type’ setting will be removed in version 1.0. Please update your configuration accordingly.

In:

  • state nodes
  • current state nodes

I can select something else, but not sure what to do:

2 Likes

It has essentially been moved. Right above that you’ll see a new dropdown next to state. If it was set to boolean, set it to boolean above.

1 Like

Also, make sure you’re running at least version 0.79.4, as earlier versions contained a related bug.

3 Likes

I updated the node red websocket to 0.79.4 and fixed all of the 20 reported configuration nodes, however the warning persists. Deselecting “Show Hidden” makes no difference (as none are hidden, and I’d like to avoid that method to make this go away) and it actually re-selected itself anyway. Restarting NR also did not help. Am I missing something?

While I am guessing the warning is harmless, my OCD desire to resolve it kicks in :wink:

1 Like

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:

  1. looks up the entity / entities specified and read the HA state object for each
  2. converts the entity ‘state’ value from string to number / boolean if required
  3. performs the conditional tests - using the converted state value
  4. 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!

7 Likes

Change the State Type (in the Depreciated Settings) to “string” and the error will go away. In “string” mode, the node no longer attempts to cast the entity state value at start (which is where this change is going).

You are not using a conditional test, so nothing has to change there.

You are using the entity state as the output property, to msg.volume, so yes you have to use the new feature to cast the entity state to a number.

To be quite clear (if I have got this right from testing). The ‘error message’ is there because the node has the old (now deprecated and hidden) State Type still set to “number” or “boolean”. The update does not change this, just hides it.

You have to change the State Type to “string” to a) turn off the type conversion and b) make any changes to boolean conditional tests, JSONata use of $entity().state, and any Output Property that uses entity state to re-set the state value type casting at this point.

@Biscuit Yes, I confirm that setting the hidden type back to string makes the error go away. I changed the new casting feature to match what the hidden one said but based on the super helpful information you provided, I have a lot of work to validate all my flows (all of my automation is exclusively in NR so I have A LOT to review :grimacing:

1 Like

Yup. I took me a while yesterday to work out what was going on, and effort to write this lot up, but my gut feeling is that when the NR HA add-on gets updated to include v 0.79+ there will be many who will benefit!

I think it is worth pointing out that

  • you don’t actually have to do anything, as long as you can put up with the error messages
  • you can take your time: for most nodes it is a simple case of changing the deprecated State Type field (to ‘string’)
  • only if you have been using “boolean” conversion will there be any need to look at conditional tests
  • only if you have been using JSONata (as I do) will there be any need to review this code
  • only if you have been using the entity state value as an output property, and have this set to ‘number’ or ‘boolean’, will there be any need to change the output property setting
3 Likes

Great writeup as always.

Just a few clarifications:

  • The deprecation notices should disappear immediately after deploying. There’s no need to wait. If they persist, there’s still an issue present.
  • In the original State Type: Boolean, the state was cast to either true or false based on the values defined in the server config. If the entity’s state matched any listed value, it was true; if it didn’t match anything, it was false.

I hadn’t considered that the use of $entity().state inside a JSONata expression could cause issues with this change. I rarely used the old “state type” setting myself and got used to relying on $number instead.

1 Like

Thanks. Of course the best person to ask is you!

I just happened to update my development Raspberry PI Node-RED instance to node 22 with a full palette update at the weekend, otherwise I would not have seen this for quite some time.

  • Deprecation notices (error messages)

My development instance is full of stuff, but as a habit when I move on I disable most WebSocket nodes, and the message does not appear for these. Disabling an ‘errored’ node and redeploying also normally removes the message right away. I was repeatedly changing node settings and redeploying to test the changes, and in this case the message becomes sticky, and I found that it will only go if the State Type setting is “string” and I re-start Node-RED. I was assuming that this is because I am constantly changing the same node, and that the error checking routine could not keep up.

  • $entity().state JSONata expression

In an Event:state node, using JSONata as the condition test-option, yes the return from $entity().state is a number when State Type is “number”, and a string when “string” [and boolean likewise]. Using the raw returned value thus has to change, for example $entity().state>300 works for “number” but generates the expected JSONata error,

The values “351” and 300 either side of operator “>” must be of the same data type

and needs changing to $number($entity().state)>300

I agree that almost no-one will be doing this, but I mentioned it just in case.

What to change here then:

And this one?

change “as string” to as number?
change number to string?

feels a bit un-intuitive

1 Like

Yes.

For each ‘state’ node [where you currently have State Type as ‘number’]:

Change Deprecated Settings - State Type

  • from “number”
  • to “string”

This turns off the entity state-value casting when the node starts.
[so now the node - conditional tests etc - will always be working with the entity-state value as a string, and no longer as a number]

For the Current State node:
Change Output properties - for msg.payload = entity state

  • from “as string”
  • to “as number”

This [if you need it] turns back on the state-value casting at the generation of output properties. [so the output property msg.payload will continue to have a number rather than a string as it did before]

Your conditional test, as < 40 uses a number literal but will still work (with the entity state as a string) so no change is required there.

  • The deprecation notices should disappear immediately after deploying. There’s no need to wait. If they persist, there’s still an issue present.

I continue to get numerous “Nodes with issues” like the one below. The sensor is originating from an ESPHome device and has a State value of 7.65299987792969:
state_class: total_increasing
unit_of_measurement: gal
device_class: water
icon: mdi:pulse
friendly_name: irrigation-meter-valves Irrigation Water Total

I understand that the actual state value is a string and I’m changing the output value to a number, but don’t understand why it still shows an error.

These are Kermit’s nodes, and I have only been tinkering with this on my development instance, but I have found the ‘nodes with issues’ can be sticky, and also not all nodes with issues are being shown.

You may find, as I have, that restarting Node-RED forces the ‘node-issue’ routine to clear and re-check, and this for me has cleared any ‘sticky messages’.

Indeed - a restart of Node Red does update (reduce) the number of errors shown after making the changes.

Thanks!

It’s odd that all of my nodes with the error defaulted to “State Type: Boolean”, forcing me to change all of them to ‘String’. I don’t think any of my nodes checked for or output boolean values, yet I had over 150 nodes flagged with errors that defaulted to boolean.

And what about this one?

It is currently like this:

Well yes, that one is a bit more tricky.

I will attempt to cover this (pun) in detail, so that you and others can work the rest out for yourselves.

You have a cover entity. These normally have an entity state that is a string as “open” or “closed”. This is nominally boolean, but clearly Home Assistant treats it as a string with two distinct values.

A Current State node

Original situation:

  • the State Type setting was set to “boolean” [and actually still is].
  • using the boolean string in the HA Server Configuration node, the node converted (cast) the entity-state value from string to boolean true if the original entity state was “open”, or to false if the original state was “closed”
  • this entity.state value (boolean) was available in the node
  • you are using JSONata in the ‘If State’ condition, but your expression $entity().attributes.current_position > 20 is reading the entity attributes, which is not the entity state.
  • you do have output properties with entity, that return the entire entity object, but you do not have an output property with entity state.

Future position:

We need to turn off the entity-state casting from “string” to “boolean” (either now or at some point in the near future, so you might as well do it now).

  • turn State Type to “string”
    • this turns off the entity state casting from string to boolean
    • this will remove the “error message”
    • note: at some point, the State Type UI entry will go entirely, but you will no longer have to worry about this setting ever again

Now we have turned off the entity state casting for the node, the node will be working with a string and not a boolean, so we need to check:

  • will this effect the condition testing in ‘If State’?
    • no it will not, since you are not reading $entity().state in your JSONata
    • so you do not have to do anything here
  • will this effect any output property for the node?
    • no it will not, since you do not have any output property set to entity state | string
    • if you did, you would change this to show entity state | Home Assistant boolean so that the output property continued to be cast (converted) from a string (“open”/“close”) to a boolean (true/false) value, using the Home Assistant boolean rules

Possible issues:

The only other problem that you may experience, is from the use of the msg.data.original_state and the msg.data output properties, which are both set to use the entity object.

The node entity object contains everything about the entity, including the entity state. The side-effect of the state-casting is that the entity state value was changed in this object at the start of the node.

This means that, before changing the State Type, msg.data.state will be boolean
This means that after changing the State type, msg.data.state will be a string.

If you are using msg.data in the subsequent flow, you will now have “open”/“closed” and not true/false

You will need to consider any use of the full entity object later in your flow. In the new situation, entity state casting does not apply to the entire entity object, and can only be applied to the state value itself.

If you used the entity state, with the Home Assistant boolean option, then you would have the state value cast to boolean.

Picture:
Top (before) - State Type set to boolean. The msg.payload (entity.state) is true, the msg.data (entity) object has state true, and there is an original_state object as “open” [which was the original entity state the node saw before casting the state to boolean]
Bottom (after changes) - State Type set to string, msg.payload set to entity.state | Home Assistant boolean, the msg.data (entity) object now has state “open”, since no state casting is taking place. msg.payload continues to have the value cast to boolean, using the Home Assisant ‘rules’

I hope that addresses your question fully and correctly.

I have now opened a bottle of something nice, so this UK helpdesk is now closed and the USA helpdesk will take over :wink:

OMG… so much info. Thank you for taking the time to help and write up. I think the summary is to just change to string and save…?