Usage of switch node as previous msg.payload and HA entity state comparison

Hello, I have created some template sensors to re-format the date/time of the sun.sun attribute to only hh:mmAM/PM as below.

The next step I want to do is to use node-red to compare the current time with the above sensors. If both time matches then change the time of day helper. The inject node below trigger every 5 seconds (For now it is just in dev so i use pushover instead of changing helper state)

Time Convert node does it job. The time format matches the template sensors mentioned above.

The problem is the Switch node, I want to compare the msg.payload parsed from previous “Time Convert” node with sensor.nextdawn for example. If matched then go out from output1 etc.

The JSONata expression is as follow:

payload=$number($globalContext(‘homeassistant’).HomeAssistant).state.“sensor.nextdawn”.state

When both msg.payload (current time) and sensor.nextdawn.state matches, eg: 6:11AM for dawn, I do not receive any pushover notification.

The function nodes are just format the pushover message , no issue there.

Does the above JSONata expression i create correct? The name of HA in my node-red setup is called HomeAssistant, and I have checked “Enable Global Context Store”.

HA

Really appreciate if anyone can shed some lights on this. Thanks!!!

Doesn’t cast to a number. Also the payload from the time formatter is a string. If you remove $number() it should work.

If I could suggest putting the original sensor from the sun component in a time node set to daily, will fire at the time in the sensors value.

@Mikefila Thank you for the suggestion, let me see if I can follow your idea.

Consider using the time node, which can trigger based on a timestamp from a Home Assistant entity attribute. This way, the flow only activates at the specified time, avoiding the need for a constant trigger every second.

image

@Kermit I see, This is way better than what i have made in node-red. Thank you very much!