General understanding of the ‘current state’ node

I have a problem understanding the ‘current state’ node. Set to check if the light level of a sensor is equal or less than 100, and a state type set to boolean I get two outputs channels: ‘if true’ and ‘if false’.
I would expect, that there is nothing coming out of the ‘if true’ channel if the sensor measures more than 100 lux, but there is output: false!
So, if I connect thereafter a call service to turn on a light source, then the light will be turned on because through the ‘if true’ channel comes the signal ‘false’.

Is there something going wrong? I am running on version 2.2.0 on home assistant add-on version 11.0.1

[{"id":"51169996390fa340","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"0df060dcc990f7a7","type":"inject","z":"51169996390fa340","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":290,"wires":[["16c169eda288cf66"]]},{"id":"16c169eda288cf66","type":"api-current-state","z":"51169996390fa340","name":"Light level <= 100","server":"164cb1b.35ebe4e","version":3,"outputs":2,"halt_if":"100","halt_if_type":"num","halt_if_compare":"lte","entity_id":"sensor.outdoor_motion_sensor_terrace_2_light_level","state_type":"habool","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":530,"y":290,"wires":[["f476e7ce96bcc660"],[]]},{"id":"f476e7ce96bcc660","type":"debug","z":"51169996390fa340","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":290,"wires":[]},{"id":"164cb1b.35ebe4e","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

The state is not boolean.

sensor.outdoor_motion_sensor_terrace_2_light_level has a number as the state, but HA states is always string.
That means the state type should be string.

I actually never change that setting.

The false messages/values is on the lower point:

2 Likes

Thanks @Hellis81 I just checked the documentation for the node… of course you are right! Since I am fairly new to NodeRed and HA, but have a good share of programming experience, I dare to ask why the user has the option to select a state type at all, if the type is fixed to string.

Cheers Thomas

1 Like

I have no clue.
Possibly you can have it set to boolean if you are using a input_boolean. But as I said, I have never changed that setting.

A lot of the states that are numbers come over from home assistant a strings, numbers can be strings but strings can’t be numbers. So it allows you to make a conversion in the node.

from the info bar:

Convert the state of the entity to the selected type. Boolean will be converted to true based on if the string is equal by default to (y|yes|true|on|home|open).

If an entity has a state of y|yes|true|on|home|open it will automatically change it to a true or false boolean. This can help simplify flows.

1 Like

Thanks @Mikefila for the explanation.
Maybe it’s just me, but with respect to the boolean value returned, I do not get why there are two output channels. Especially since both of them return the same value. From what I see at other nodes the behaviour normally is that ‘false’ gets piped into the channel for ‘If State is false’, while true goes into the ‘If State is true’ channel.
In case that’s not possible to achieve I would say it is better to have only one output channel in case of a boolean value as state type.

The top output when there are 2 outputs, will send the configured value through the top output.

If the node is set to trigger on false, false comes from the top.

If it is set to true then true will come from the top.