Template switch switchtes itself off after 10-15 minutes

My goal was to create a switch that indicate a certain mode to be active.
So far I have created a switch for this, combined with hass variables https://github.com/rogro82/hass-variables. The switch is defined initially off, so when I switch it on, I would expect it to be on until it is switched off again. The hass variable should make it persistent over restart as well. However, When I switch this on, it will magically switch off again within 10-15 minutes…
How is that possible and what can I do to avoid that?

This is in my configuration.yaml:

    value: 'off'

  - platform: template
        value_template: "{{ states.variable.mode.state }}"
          service: variable.set_variable
            variable: 'mode'
            value: 'on'
          service: variable.set_variable
            variable: 'mode'
            value: 'off'

Are you sure you don’t have another automation or something else controlling the state of that switch?

It seems strange that it’s a 10 or 15 minute delay. If the config was wrong it would not work at all or switch back off immediately.

Yes I am sure. And yes it is strange…
maybe someone can try my example or similar and report if this happens elsewhere also…

There must be something… My log says:

Not passing an entity ID to a service to target all entities is deprecated. 
Update your call to switch.turn_off to be instead: entity_id: all

I do have an automation that refers to a group like the one below, Works fine, but maybe the group switch does something that has become depricated, and therefore now also switches my template switch?

  - entity_id: group.lights_living
    service: light.turn_off

You’re using the wrong service to turn off a group.

            GROUP DOMAIN
 action:         |
  - entity_id: group.lights_living
    service: light.turn_off
            LIGHT DOMAIN

and group doesn’t have a service dedicated to turning itself off so you need to use the blanket ‘homeassistant.turn_off’ service.

I don’t believe that is related to your issue but it will remove your warning.

Thanks! This indeed removed the warning, but does not fix the topic issue…

I just installed your exact code above into my system and turned the switch on and it has been on for 25 minutes so far.

You probably have something else going on that is causing the variable to get set to off.

1 Like

I found it. Somewhere in a package the entity was not mentioned… Thank you for setting up a reference !