Current State - IF data.attributes.current_position

Hello, absolute beginner here (running HA/NodeRed for 3 days now).

So I just installed a Shelly 2.5 for one of my roller shutter and I already made some flows with it. But now I’m running into a probably simple problem (for you guys) that I just can’t solve myself.

I simply want to use the “current state” node to check the current position of the Shelly. This information is stored in “data.attributes.current_position” ->

How do I use this now? I tried it several ways, but I guess I’m too stupid :smiley: Guessing that Im doing it completely wrong? I want to use it like “IF the current Position of the Shelly is at 90”

The background is, that I never completely close my roller shutters. My personal “closed” is at 85%. But obviously the Shelly entity itself shows “open” and only switches to “closed” if its at 100%. So I want a Flow like

“some imput” -> “current state: Is the shelly roller shutter at 85%?” -> IF YES -> Do This

So i guess, something like this:

condition: template
  value_template: '{{ states.cover.your_cover_entity.attributes.current_position < 30 }}'

image

https://community.home-assistant.io/t/jsonata-examples-for-ha-nodes/128963?u=kermit

3 Likes

Thanks!
Also I want to note that I figured out yet another way. I just attached a switch and can now use the outcome of that.

Next time Im gonna try Kermits solution :3

Edit: Nah, switched my solution out and 'am now using Kermits approach. Way cleaner :'D

Has this syntax changed?
Currently, I am unable to get node red to pay attention to any attribute for state changed node, it will only look at whether it is on or off.

Scratch that, had to remove ‘.data.’ from the string.

Hey, I have a light wiht brigtness and I want a true if the brightness is set to 50%/129. I use the following:

$entity().attributes.brightness=129

But it does not work. It send allways 1/false. Whats wrong?

1 Like

State type only converts the state of the entity.

Use the same JSONata expression you have in Output Properties.

image

2 Likes

Thank you very much! Now it works!

Hello mate,

how did you sort it out?

for example on the if State field I placed
image

$entity().attributes.noise_detected=on

this is if my camera detects sound
but what have you placed in the output properties?

I’m also always getting “false” in the output

What is wrong here?

image

Use quotes around on

Something is not right

Can you help?

image

Also the node is not sending information to the debug when the attribute changes. The state of the entity is always on idle. How can the change in the attribute from ‘off’ to ‘on’ force the node to send a payload?

Any help, anyone please?

If the state of the camera is always on there is something wrong with the config of the camera.

@kermit from the JSON value you have given in the example, is it possible to reference another entities value, eg inpute_number? ie evaluate IF the current position is less than the input_number wanted position THEN output true? Would the following work?

$entity().attributes.current_position < input_number.wanted_position

$entity().attributes.current_position < $number($entities("input_number.wanted_position").state)

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/jsonata.html

1 Like

Thank you so much

Does anyone know how to fix the issue with the call-back error in the latest version of NR?

I have JSONata expression = $entity().attributes.current_position > 20
But it no longer passes a true/false and throws a debug error = Error: JSONata Error: Calls to RED.util.evaluateJSONataExpression must include a callback.

1 Like

Make sure you have the latest version of node-red-contrib-home-assistant-websocket in Node-RED
image

1 Like