Current State node - attributes

Hi,

I am breaking my head and probably overthinking. i am trying to achieve the following.

Based on the state of a window blind (cover) I am trying to switch on or off a light. Cover <20% is off, >20% is on.

But the cover is a z-wave device integrated in hass via the vera integration (on the role to migrate but other point). So the cover presents its self in hass like:

now I am trying to use the “current state node” to select what output to use and switch:

But obviously I am only getting open/close as the hass state.

How can I use the attribute “current_position”?

i think your flow is triggered by something else, and based on the cover % of the blinds, you want the light turned on or off?

if State can also use JSONata that evaluates true or false. here it is based on the brightness of the light.

image

Yes. If I do that I use the attribute in json:

But it keeps giving me “open” in the debug outpu… not giving me the input (on/off).

edit:
this seems to do it:
image

Using data.attributes.current_position > 80 you’re checking against the message object, msg.data.attributes.current_position. If you want to check against the entity that you have defined in the current state node you’ll want to use $entity().attributes.current_position > 80.

3 Likes

Oh I am really overthinking this. I want to achieve the following very simple…

Based on the attribute “current_position” and the dusk dawn I want a light to be on or off.

IF cover < 20% and DAY = light OFF.
IF cover > 20% and DAY = light OFF.
IF cover < 20% and NIGHT = light OFF.
IF cover > 20% and NIGHT = light ON.

What should be the starter in the flow? The dusk/dawn bigtimer node? the cover position? i am really breaking my head :slight_smile:

if you put it in plain language:

  • when the sun rises, turn off the lights whatever the position of the cover.
  • when the sun sets, if blinds are covered more than 20%, turn the light on
  • when the sun sets, if blinds are covered less than 20%, turn the light off

what happens after sun set, you change blinds from 50% to 10% do you want the lights to be turned on or no action?

I think the problem lies in the way the logic in node-red works. Following your logic above it is fired and forgotten. I want it to be dunamic. Thus if the sun is set AND the blinds are moving between 20-40% I want the light to go on an off…

I have this logic currently running in Vera in “PLEG” and this works well over years. But I want to move all logic to node-red…

EDIT:
I think I can only solve this question if I start with trying to get an answer on the question how to use a state node and output on the “current_ position” entity. That I can’t get to work…

This output I get as a total output from the state node:
{"topic":"cover.143","payload":"open","data":{"entity_id":"cover.143","old_state":{"entity_id":"cover.143","state":"open","attributes":{"current_position":100,"Vera Device Id":143,"friendly_name":"cover","supported_features":15},"last_changed":"2020-10-31T10:39:01.262763+00:00","last_updated":"2020-10-31T15:30:14.535922+00:00","context":{"id":"91cacf243be596f2114e257dcd103f49","parent_id":null,"user_id":null},"original_state":"open","timeSinceChangedMs":17488574},"new_state":{"entity_id":"cover.143","state":"open","attributes":{"current_position":100,"Vera Device Id":143,"friendly_name":"cover","supported_features":15},"last_changed":"2020-10-31T10:39:01.262763+00:00","last_updated":"2020-10-31T15:30:14.535922+00:00","context":{"id":"91cacf243be596f2114e257dcd103f49","parent_id":null,"user_id":null},"original_state":"open","timeSinceChangedMs":17488574}},"_msgid":"e0d4dc9a.98107"}

So the main trigger is cover position and depending on the Sun position a different action to be taken. Maybe start with a trigger state node that fires when the cover goes below 20% and put a timeswitch node before the service call node.

hi all, thanks for responding and thinking along. The main question in this case was how to “act” on the attribute rather than on the state. i think I did it. High Level looks like:

Will have to monitor desired behavior in dark ::wink:

Hi @Kermit, I think and thought I had it running but this night suddenly the light was on a 00:01 and that shouldn’t have been.

I have been reading your remark over and over an added it to my node (for test).

Like:

But whatever I try, setting the cover to a position (via home assistant) etc. I wanted to make my flow simpler and add that to the state node like this:
image

But I keep getting “NaN” at the node (with or without the json code)

Any thoughts would help :slight_smile:

my guess would be because you have state type as number and the state of the cover is becoming unavailable which is unable to parsed to a number so you get NaN

So this is only a cosmetic thing?

@sender did you ever manage to read that attribute from within Node-red?

Yes I did, will tell you in september if you remind me

I’m back… a lot of things changed. Me, Node-Red, Homeassistant and my zwave (OZW to ZwaveJS) and my automation broke…

Whatever I try I can’t get it back working again and I ended up on my own post :slight_smile:

1st question: I want to simply check the state of a cover which is still reported under data.attributes.current_position. But for whatever reason this does not output correctly anymore after “a change”.

This is my node config:

@Kermit suggested to use

but that also does not do the trick here.

help?

This outputs false also:


even if it is:
image
data.attributes.current_position

Yes, got it :slight_smile:

works!

5 Likes

The above posts helped me figure out my use case (Google Calendar offset attribute) with a little trial and error. To help anyone with an Event State node, this is what worked for me:

If state = JSONata AND Expression = $entity().attributes.offset_reached = true
State type = boolean
Output properties: msg.data = event data
Ignore state change event when: Uncheck → “Current state equals previous state” (NOTE - all were unchecked)

Note that the debug output shows following structure:

Object
  > data
    > new_state
      > attributes
         > offset_payload
1 Like

Using your example, I’ve got my state comparison working. But I can’t figure out how to get the payload state that’s displayed at the bottom of the node (bottom of the screenshot below) to reflect that specific attribute. Would you happen to know what I need to adjust or is this just not supported?

1 Like

The status of the node is always going to display the state of the entity. There is no way to change that.

bummer, that’d make troubleshooting easier if you can see the value you’re actually comparing to

Hi,

Have been struggling with the current state node for a while now, and maybe someone here could assist me.
I’m trying to check a attribute as the other before me.
Have this config:
image

This is the entity attributes:
image

But the state node still send out on the “false” output.
image

What am I missing?

1 Like