Template default value

Is there a way to have my sensor template default to a value after a 3 seconds, this is what I’m using so far

- platform: template
  sensors:
    button_two_state:
      friendly_name: "Button 2"
      value_template: >-
        {% if is_state('sensor.button_2', '1000') %}
          hold
        {% elif is_state('sensor.button_2', '1002') %}
          1_click
        {% elif is_state('sensor.button_2', '1004') %}
          2_click
        {% elif is_state('sensor.button_2', '1005') %}
          3_click
        {% elif is_state('sensor.button_2', '1006') %}
          4_click
        {% endif %}

any help will be greatly appreciated thanks.

This functionality would be really hard to do and it would tax your system based on how template sensors work. What are you trying to do exactly? maybe there is another way to do what you want in the long run.

i have setup a button that toggles a switch when the button has been pressed once, the template sensor will show “1_click” but if i press the button again it won’t toggle the switch until the state of the sensor changes to a different state.

Can you post your automation that uses this? I don’t think you need to have it reset the state.

This is what im using to toggle my switch

  - alias: Turn on Heated Blanket
    trigger:
    - platform: state
        entity_id: sensor.button_two_state
        to: '1_click'
    action:
      service: switch.toggle
      entity_id: switch.heated_blanket

I’m not entirely sure why you even need the template sensor if your sensor.button_2 has individual states for each click type. Simply using the to: state method should work even if you are going from the same state to the same state. The only possibility is if your device is suppressing the second click a few moments later. Have you tried looking at the logs and seeing if the event for the second click is coming through?

1 Like