Thanks, not sure whats wrong here, tried to use the code from link
Maybe because its a switch and not a sensor ?
- platform: time_date
display_options:
- 'time'
- platform: template
sensors:
greenhouse_last_connected:
value_template: >-
{% set value = states('switch.greenhouse') %}
{% set last_updated = as_timestamp(strptime(value, "%Y-%m-%d %H:%M:%S")) %}
{% set seconds = now().timestamp()-last_updated %}
{% set hours = seconds / 3600 %}
{% if seconds / ( 60 * 60 ) > 1 %}
{{ seconds // ( 60 * 60 ) }} hours ago
{% else %}
{{ seconds // 60 }} minutes ago
{% endif %}