Time function as trigger in a flow

Hello all

although i extemly new to node red and i'm not an it guy i want to learn how to build automation in node red within Home Assistant.

I have contracted 4 flows that cover lights climate control geofencing and finally media environment control.

I will continue to improve and extend these flows to allow me to finetune the trigger event and the integration with other components.

They all are working fine with the exception of triggers

I use either motion, time, temperature, luminance and finally presence.

Today i would like to tweak the time environment

Based on a specific start of my automation (set at 7:00) for some reason the automation fires at 6:45

MY pc, my os, home assistant all are set to the same time zone and to daylight saving time options enabled.

Why would this happen?

Is that time set in node red or in home assistant? If in node red then what node are you using for the timing?

Thank you for your prompt reply

Time in home assistant is correct with the correct country time zone which is correct GMT +1

In Node Red i have my Geofencing, Lightis, and media and heating with times to activate from 7:00 and 23:00

and 23:30 to shutdown all

On the heating flow I use an Inject mode node whereas in other flows I use time range node.

In both I have time ranges established (7:00 to 23:00)

The inject node is at the beginning of the flow in order to establish the time range during which the flow is tunning whereas the the time range node I use in the middle of the flow. This last flow is triggered by a motion sensor and the time range are to used to define the illuminance intensity of the light

I do not see where i can set the time in Node Red ...Settings?

Thank you for your time and assistance

I believe that for such things as an inject node set to fire at a specific time, it is the time on your Node-red server that counts. When the time on the server lurches into or away from daylight saving time, the inject follows it. So an inject node firing at 07:00 will fire at 07:00 BST or 07:00 GMT.

I'm not familiar with this node. Is it node-red-contrib-time-zone-switch?

If you make a very simple inject timestamp-debug flow:
image
When you click to inject the debug pane shows the current time (as milliseconds since the world was created in 1970) as well as the time (on the browser machine?)
Clicking on the actual value cycles through various representations of the time.
image
image
image
image

If you try this do you get unsurprising results - the debug's message received time and the payload agree with each other and with your wall clock?

Thank you for this explanation

My debug node for the timestamp node shows the following

msg.payload : number

1699530275423

11/9/2023, 12:44:37 PM[node: Presance](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)msg.payload : string[4]

"home"

11/9/2023, 12:45:02 PM[node: Turn On if -19](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)msg.payload : number

1699530300005

11/9/2023, 12:45:03 PM[node: Presance](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)msg.payload : string[4]

"home"

I did cause an inject on the time stamp node and the time of the debug information line is correct with the pc time.

In my timestamp node i do have set a repeat every 5 minutes

Based upon what i see i still do not understand what i may have configure incorrectly

Now i must wait for the next trigger (climate to hit 21 deg) and see the time stamp then (in about 3 hours )

How to you obtain the 1970 millisecond number to convert into an actual time ?

Once again thank you for your time and help

The default output of the inject node is the timestamp in milliseconds.
You might find find it useful to paste the value into epochconverter.com.

Thank you for this link

so it must be done manually

Thank you for the time and help

What machine are you running node-red on? Is it a Pi connected by wifi?

Hello Colin

I'm running Node Red as an addon to Home Assistant.

Home Assistant is running as a VM on a proxmox ver 8 server which in it's turn is running on a Dell R720

The Dell, Proxmox and HA are all running on same time zone and all have the same system time. I visited Epochconverter and i see how i can translate the milliseconds to human time. I was hoping this could have been done on NR.

Thank you

It can, as has already been mentioned -

I apologise for my massive ignorance but i do not understand how

Do you see that I posted pictures of the debug node showing 4 different time representations?

  1. Milliseconds since 00:00 1st January 1970
  2. The time in Zulu time ( = GMT)
  3. The time in my local timezone (UTC = GMT = Zulu)
  4. A representation in hexadecimal

These are all the identical debug output but I clicked on the actual debug text (in blue), which causes the output to cycle through the four representations.
image

Apologies if I didn't make this clear enough before. I only discovered this feature myself quite recently.

@jbudd

Many Thank Ah that was very easy again thank you and sorry for the ignorance

Hello all

I have been tweaking my node red environment and i think i'm getting a very basic understanding on how to use it thanks to you all. Your patience and help is greatly appreciated.

11/30/2023, 12:10:27 PM[node: Light on 60%](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)binary_sensor.multisensor_6_motion_detection : msg.payload : string[3]

"3.0"

The above is an output of my node red debug for one of my lights

I do not understand what the "3.0" is

furthermore as you see from this output the light brightness is supposed to be 60% however when i verify the status of the lightbulb on the shelly app , I see initially the light off (as it should be) then when motion is detected the light tuns on at 30%

The night setting is 20% therefore i do not know where this 30% comes from.

I went to the device web page and i see that the device is at 30%.

Since my native Home assistant works (regardless of the light native setting), I feel that it is my node red instance that is incorrectly configured

The motion detection works

it then the activity passes through a time range node and one output of the node is going to day time setting (light on 60%) and the second output of the time range node goes to night time setting (light on 20%)

as suggested here above i entered {“brightness_pct”:60} for the daytime option and {“brightness_pct”:20} for the night mode in the edit call service node.

I feel that i am missing something or parameter that will cause the override the shelly lightbulb settings

should the % value be in quotes (it does not look like it)

Thank you for your time patience and help

From the debug node i do not see where this error occurs

Is this a continuation of the 'time function as trigger in a flow` or is it a different issue? If it is a different issue then it please start a new thread and make sure you explain in detail what the problem is.

Thank you for your reply @Colin

The flow is triggered by Motion detection, then checks luminance levels and finally time interval

Are you suggesting starting with the time interval would improve the flow?

In this particular flow the trigger can be time or luminance first then if motion is detected activate

Can the time range node be used as a trigger?

Howe3ver i cannot find a way add trigger/condition on motion detection. What node should i use?

I will try this

Thank you

No, I was asking if this is still the same problem as I thought your original problem was solved.

What time range node is that?
If you want to trigger events at particular times I recommend node-red-contrib-cron-plus.

The timer is called node-red-time-range-switch

This node is configured for a set time interval (07:30 to 22) and that will trigger the day/evening lights. The second output (in my opinion ) would trigger any action beyond and outside this time range to the second connection (this is where i maybe mistaking maybe i should use 2 time triggers)

I tried using this node however it does not seem to passthrough or activate the next node. I guess i still need to work on this and further understand where i made the error.

Thank you for your reply

I have not used that node, but it is quite clear in the readme, it says
If the current time falls within the range specified in the node configuration, the message is routed to output 1. Otherwise the message is routed to output 2.

Are you saying this does not happen? To check, add debug nodes showing what is going into and out of the node and see what they show.

Thank you Colin for your patience and help

The time stamp does segregate base on time the flow However I reverting back to my original flow.

I separated the day and night flow into 2 totally separate flows

In the day flow the light goes on at 60%

the night flow the light still goes on at 60%

I checked the light statius on my shelly app on my android phone, as i ran the flow.

It is evident to me that the node red flow does not override the bulb illuminance setting,

If i use the home assistant automation the illuminance of the light does change according to the time frame

Therefore I surmise that in my node red flow I must be missing a setting in the call service node where i turn on the light and ("data") in expression {“brightness_pct”:60} or {“brightness_pct”:20}
Even If i change the data expression to {} JSON it does not happen.

I really do not where to look

Here is the lares node red debug

`Preformatted text`12/1/2023, 3:26:13 PM[node: Light on 20%](http://192.168.1.112:8123/api/hassio_ingress/JeXK6fWVzk2zs66R1f1inIgAejGgIEVbYkOEpL_3X6Q/#)binary_sensor.multisensor_6_motion_detection : msg.payload : string[3]

"1.0"

Once again Colin for your help