Compare current time with input_datetime helper

How do you use an input_datetime to be checked and based on that comparison do certain actions?

I would like to be able to control when my home does something by adjusting the input_datetime helper in the Lovelace UI. Currently, I am using timerange nodes to handle if the time is between certain times and then do different birghtness levels for lights.

This is great except when we decide to host festivities and it goes beyond the hard coded timerange resulting in the house shutting down the party. Boo!

Example what I am hoping to achieve:

Motion -> input_datetime helper compared to current time -> action 1 -> lights 100%
                                                         -> action 2 -> lights 1%

Thoughts outside of a custom function?

Edit: other solution.

Best way is to add both a timestamp as a msg.object and the global value of you input_datetime helper.
Those two values can then be used in a switch node.

[{"id":"cc2423d5e8eab31b","type":"server-state-changed","z":"be03f9025a1f137a","name":"test","server":"541ade28.b4a62","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"person.guest","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"home","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"sleepy","propertyType":"msg","value":"homeassistant.homeAssistant.states[\"sun.sun\"].state","valueType":"global"},{"property":"now","propertyType":"msg","value":"","valueType":"date"}],"x":730,"y":735,"wires":[["bb56a3f7cd346eef"],["e422c111f2431596"]]},{"id":"541ade28.b4a62","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"numeric","statusMonth":"2-digit","statusDay":"2-digit","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Appreciate the thought on this. Your example is based off an event. I am needing to compare within the flow and replace the timerange node which currently determines how lights react. Any thoughts on using maybe a current state node or something similar?

The extra fields I inserted in the node should be possible to move to any node.

1 Like

I am making headway and I believe I am almost there. My initial tests are working with the switch node comparing if the “homesleep” is between “now” and a specific hardcoded time. With your wisdom I was able to acquire the start of morning and evening but I need to convert the system time to the same as now and homesleep. What would I need to do to the “Test” node (image below) to format the pulled states to a time value that I could compare like I did with “homesleep” and “now.”

[{"id":"91e7412cda7af7b3","type":"inject","z":"8cc610aa01707cda","name":"","props":[{"p":"payload"},{"p":"now","v":"( $now('[H01]:[m01]:00', '-0700') )","vt":"jsonata"},{"p":"homesleep","v":"homeassistant.homeAssistant.states[\"input_datetime.house_bedtime\"].state","vt":"global"},{"p":"evening","v":"homeassistant.homeAssistant.states[\"sun.sun\"].attributes.next_setting","vt":"global"},{"p":"morning","v":"homeassistant.homeAssistant.states[\"sun.sun\"].attributes.next_rising","vt":"global"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Test","payloadType":"str","x":130,"y":160,"wires":[["b9e0bca994e25e36","06111061c9c266e6"]]},{"id":"b9e0bca994e25e36","type":"switch","z":"8cc610aa01707cda","name":"Time Ranges","property":"now","propertyType":"msg","rules":[{"t":"btwn","v":"homesleep","vt":"msg","v2":"15:31:00","v2t":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":370,"y":160,"wires":[["fb153a7bf2794378"],["9c30abe41c816eb1"]]},{"id":"06111061c9c266e6","type":"debug","z":"8cc610aa01707cda","name":"debug 9","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":520,"y":40,"wires":[]},{"id":"fb153a7bf2794378","type":"debug","z":"8cc610aa01707cda","name":"True","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":510,"y":120,"wires":[]},{"id":"9c30abe41c816eb1","type":"debug","z":"8cc610aa01707cda","name":"False","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":510,"y":200,"wires":[]}]

Out an extra object in the test node with the value timestamp, then you have the now in a timevalue.

I need to change the timevalue of both the evening and morning values from sun.sun to HH:MM:00 as the input helper is formatted that way.

input_helper entity:

sun.sun entity:

Look here: Date & Time Node Example

1 Like