How to reference a value from an entity in Javascript code in function node

Hi,
Most likely a stupid question but despite all my searches I could not find the solution.
I want to use nodered to trigger flows, but most of the “intelligence” will be in a function node through Javascript code.
I’m able to access the values related to the entity which triggered the flow : for instance a Zwave remote control.
In the javascript triggered by the remote control, i want to check if my roller shutter (also connected through Zwave) is already moving up or down. To achieve this I need to access the attribute “value” of the power entity related to the roller shutter.

Another use case, I want to play TTS messages to my Sonos. But before I want to store the being played playlist, before broadcasting the TTS message and then after resume the playlist on the Sonos.

thanks

Hi,
if I get you right, you can use a current_state node to get the state of any entity in Home Assistant during your flow. With “state location” and “entity location” you can specify where the data is stored and from there you can access it through the function node.



image

The debug node is useful to see, which attributes exist.

Thanks a lot @tobi-bo,
It is not exactly what I was looking, but your answer allowed me to find an acceptable solution. So thanks again !

For your reference, I was aiming at having a very simple nodered flow where there are 3 nodes:

  • a first one (event node) with the event which triggers the flow (in my case a zwave remote control)
  • a second one (function node) to handle the event, take a decision and format the payload for the next node
  • a third one that is a service call node.

In that manner, I can concentrate most of the intelligence of the flow into the function node thanks to Javascript code. I find it easier to maintain and make evolve.

In my use case, in node 2, thanks to Javascript:

  • I read the event triggered in the first node = which key has been pressed and hwo (1 time, 2 times, Key hold etc…). These information are passed in topic and payload coming from node 1. this allows me to define which roller shutter I want to control.
  • I decide what to do, I want to check if the roller shutter I’m controlling is already going up or down or if it is stopped. For that I need to read its instantaneous power.
    I was therefore looking if there was a way to access the instantaneous power of the roller shutter direclty from Javacript function, like any other Javascript variable …

Anyway thanks again.

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/config-server.html#context-example

Thanks @Kermit for pinpointing to the right section of the doc (I was kind of lost there).
I tested it and it works like a charm. :pray: