How do I act on an object's "state attributes"?

I’m trying to make a trigger based on sun.sun’s “azimuth” location. Like this:


When the sun’s azimuth hits “210”, I want my shades to drop.
So I’m passing the entire sun.sun’s object status to “azimuth switch”:
image
But nothing happens.
Am I addressing the sun’s azimuth object incorrectly? How can I make a trigger when it hits “210”?
Thank you!

Specifically, how do I do this below in Node-Red??

automation:
alias: “Exterior Lighting on when dark outside”
trigger:
platform: numeric_state
entity_id: sun.sun
attribute: azimuth
# Can be a positive or negative number
above: 120
action:
service: switch.turn_on
entity_id: switch.exterior_lighting

image

[{"id":"54c5160c.ba8878","type":"server-state-changed","z":"f61766ce.f85398","name":"","server":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sun.sun","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":258,"y":2480,"wires":[["c5127757.c42b58"]]},{"id":"3a13c8d5.02c8c8","type":"debug","z":"f61766ce.f85398","name":"do stuff","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":588,"y":2480,"wires":[]},{"id":"c5127757.c42b58","type":"switch","z":"f61766ce.f85398","name":"","property":"data.attributes.azimuth","propertyType":"msg","rules":[{"t":"gt","v":"120","vt":"num"},{"t":"lt","v":"120","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":434,"y":2480,"wires":[["3a13c8d5.02c8c8"],["3a13c8d5.02c8c8"]]}]

Argh
Thanks Kermit, that’s pretty much exactly what I have in node red as you see above. But it doesn’t do anything.
But you confirm that the structure msg.data.attributes.azimuth is correct? Attributes is plural (even though yaml is singular)?
Also maybe I need to change the state to “number” rather than “string”?
I wish node red made this part easier. Wish each object attribute could be on a pull-down menu!!

Here is my state node:

In your example do you have Current state equals previous state unchecked? The sun.sun doesn’t change state each time an attribute is updated.

Use a debug node after the event state node and output msg.data and you’ll be able to see the structure of the object.

I have a similar automation, and I use a “trigger: state” node to kick off the automation when the sun is below 4 degrees elevation. Here’s the “Conditions” section I use for that:

jdntx,
Fantastic, thank you. I wonder why this works but “events: state” doesn’t.

1 Like

So can someone tell me what is wrong with this switch node grammar?
I’m trying to switch based on the azimuth attribute of sun.sun:
data.attributes.azimuth looks correct from the debug data, but this property field doesn’t act like it recognizes any of this object at all.

image

Just a guess: have you tried data.new_state.attributes.azimuth? That seems to be where it shows up when I hooked up a state_changed node.

The full path copied from object debug is:
data.event.new_state.attributes.azimuth
But that path gives me a property error. Why do they make it so hard to guess how to address a property??