How can I read the state of a light entity in a function block?

Hi there,

I’m pretty new to hassio and node-red. For the last couple of weeks I’ve playing with lights and switches to control them and to automatically turn them on on the lowest possible brightness when I need to wake up and turn them of when I think no one is at home again… At this point I got a some function-nodes to enrich payloads.

For my next test-flow I need to determine the state (on/off) of a variable amount of lights.
So…I want to read the state of those light entities in a function block. Can that be done?
And to extend the question… Is it possible to read any state from any light or sensor in a function block… I know I can use the current-state-node but not always handy in more complex situations

Regards
Sjoerd

I’m not sure, possibly someone clever will say you can.

If not, use a current_state_node to set a variable (msg, flow, or even global) that you can query in the function.

Could you perhaps provide a little example? Bit puzzled how to tie that together.

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

1 Like

@Kermit According to that page: I created an extra server using the all-events node and let it talk to the base url. I also created a long live access token (pointed out here). Then the example worked quite well. I think I can work my way from here.
Thanks !!

Thanks!!! I was looking for this.
It helped me superb