Flow to work around new uptime integration?

I have a number of flows that rely on the “old” style uptime integration which will no longer work once I upgrade to HA 2020.12.
Does anyone have any ideas on deriving uptime duration from the new format?

2 Likes

Just create a new sensor based on the uptime sensor, then use the new sensor on Node Red.

- platform: uptime
  name: "HA Uptime"

- platform: template
  sensors:
    ha_runtime:
      friendly_name: "Home Assistant Runtime"
      value_template: >
        {{ (((as_timestamp(now()) - as_timestamp(states('sensor.ha_uptime'))) ) /60  ) | int  }}

1 Like

Thanks, @oriolism I had considered that but I was hoping to create a NR function instead of yet another entry in my sensors.yaml! :wink:
However, I will try this out today as it will at least solve the immediate problem whie I hone my NR function writing skills!

Thanks again.

[{"id":"8ec67801.86e638","type":"inject","z":"ffbd7f06.4a014","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":412,"y":1568,"wires":[["4d7725f5.e47ebc"]]},{"id":"5493e672.7b7de8","type":"debug","z":"ffbd7f06.4a014","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":712,"y":1568,"wires":[]},{"id":"4d7725f5.e47ebc","type":"function","z":"ffbd7f06.4a014","name":"","func":"const states = global.get(\"homeassistant\").homeAssistant.states; \nconst started = new Date(states['sensor.uptime'].state);\nmsg.payload = (Date.now() - started) / 60000;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":558,"y":1568,"wires":[["5493e672.7b7de8"]]},{"id":"40d040b3.284f6","type":"inject","z":"ffbd7f06.4a014","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":414,"y":1616,"wires":[["abbe961b.cc9ff8"]]},{"id":"cd90bf80.a2274","type":"debug","z":"ffbd7f06.4a014","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1000,"y":1616,"wires":[]},{"id":"6b9255ce.3a467c","type":"change","z":"ffbd7f06.4a014","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"($millis() - $toMillis(payload)) / 60000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":834,"y":1616,"wires":[["cd90bf80.a2274"]]},{"id":"abbe961b.cc9ff8","type":"api-current-state","z":"ffbd7f06.4a014","name":"","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.uptime","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"","override_data":"none","blockInputOverrides":false,"x":618,"y":1616,"wires":[["6b9255ce.3a467c"]]}]
5 Likes

Thanks @Kermit. Obviously a man of few words, but your flows speak for themselves! Both options work great, appreciated.

Why doesn’t this function work anymore?

image

the binary_sensor.updater entity does contain that information in mls by default… you don’t need any extra entities nor any integration

[{"id":"69b85932591dd665","type":"api-current-state","z":"878e74c2.7f39c8","name":"","server":"9405c3fe.d0a6c","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.updater","state_type":"str","blockInputOverrides":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":590,"y":260,"wires":[["1470f015c2743e5b"]]},{"id":"8f10ff5e4512bb67","type":"inject","z":"878e74c2.7f39c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":340,"y":260,"wires":[["69b85932591dd665"]]},{"id":"1470f015c2743e5b","type":"debug","z":"878e74c2.7f39c8","name":"debug 42","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"data.timeSinceChangedMs","targetType":"msg","statusVal":"","statusType":"auto","x":820,"y":260,"wires":[]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]