Node-red - using the switch node

Hi,

I want to check if any of my lamps is unavailable (which it becomes when someone turn of the light using the wall switch).

My idea is to use the events: all node to catch all lamps and not have to specify all lamps with separate nodes.

After the events: all node I want to have a switch node that checks if the new_state of an object is “unavailable”. However for testing purposes I want to catch state_changes where the new_state is “on” (because it is easier to test). What I am doing now is just to end the process with a debug node to see if the message passes through.

The debug node events: all node sends the following payload when I turn one of my lamps on:

Skärmavbild 2019-02-08 kl. 18.16.21

I want the switch to test that the state under new_state is “on”.

I do not know how to set up the switch node to make that test.

I found it: the reference is msg.payload.event.new_state.state

1 Like

Now for a follow-up question.

I want to notify my iPhone (which works fine - I have verified it by sending a simple text message) with a message (which renders an error) that is:

the entity_id is in the new state

I do not know how to write this correctly in the Data-section of the node.

I have tried:

{ “message”:"{{ payload.entity_id }} is {{ payload.event.new_state.state }}" }

I have tried the following (alternatives to payload.entity_id)

  • entity.id
  • state.entity_id
  • state.payload.entity_id

I get the same error:

“Error call service, home assistant api error. Error Message: Unknown error”

Would be great if somebody could solve my final problem!

Also this is now resolved. The correct reference was payload.entity_id

The issue was that I had not checked the Render templates in Data box.

Easy when you know it…

2 Likes