If I just test {{(as_timestamp(now())-as_timestamp(states.group.motion_indoors.last_updated)) | round(0)}} in the dev-template console, it works. However when I use the sensor below it does not work correctly in the UI (just stays at 0s). See screenshots below.
I’m happy I have a working solution but I conceptually struggle to understand. Why would the original example not work? By defenition you would expect the sensor to update as the now() is a state change.
a sensor (including templatesensors) are updated at a certain time.
the entity you give in the template sensor is needed to update the template sensor.
you like your templatesensor to update as regular as possible, thats why you use the date_time sensor as base entity.
you could also use your motion sensor as base entity for your template but then it would only update when your motion was updated.
now() is not a sensor, so that isnt updated at all. now() has no event. it is just a calculation.
to get the time event in HASS you Always need the date_time sensor. it is created for that i think.
i think that documentation in HASS fails on more then one place
i would like to change that but for that is my english not good enough.
in some places entitynames are rewritten. spaces, dots and some other characters are changed to underscores.
sometimes that gives a double underscore.
i dont know the code behind the date_time sensor, but i think that the double underscore comes from that.
if i remember correct a single underscore can sometimes be replaced by a double underscore to know afterwards that a single one was originaly there. so that by retranslating the single underscore gets translated to a space and the double underscore get translated to an underscore.