I’m working on my irrigation automatization. There are some switches which control the valves. I’d like to show on the UI when was a switch ON last time for more than X minutes. The reason for more than X minutes that sometimes I check the system and in this case it is not a real watering when the switch is ‘ON’ for 1-2 minutes.
Also it is important to keep the last run date and time after the Home Assistant is rebooted because I’d like to use it for other automations and sometimes I reboot my HA.
I think I should make a template sensor.
Can anybody help?
Use the state trigger “on” with for x minutes.
Then as action set a datetime helper with “{{ now() }}”
Thanks a lot! It is the solution. To be honest I tried it before but I wanted to use Node-Ren. Unfortunately somehow Node-Red doesn’t accept the “timestamp”:"{{ now().timestamp() }}" JSON
Use the template node:
[{"id":"bdb27cbdaffa2ba9","type":"api-render-template","z":"ebaa69a9.649708","name":"","server":"4bbca37b.1700ec","version":0,"template":"{{ now().timestamp() }}","resultsLocation":"payload","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":450,"y":660,"wires":[["d55df5b4394adc41"]]},{"id":"9a6bea4a82226682","type":"inject","z":"ebaa69a9.649708","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":660,"wires":[["bdb27cbdaffa2ba9"]]},{"id":"d55df5b4394adc41","type":"debug","z":"ebaa69a9.649708","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":660,"wires":[]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
Thanks a lot! But what would be in the “call service” node?
I think you can use json:
{ "timestamp": "{{payload}}" }