Time-based numeric counter custom component

I tried this:
I created an input_number in slider mode and, when I move the slider, the current_position attribute of cover_sala (below) gets the correct selected value, but cover doesn’t start.

Where am I wrong?


cover:
  - platform: template
    covers:
      sala:
        # ...
        position_template: '{{ (states.input_number.slider_tapparella_sala.state|int) }}'
        set_cover_position:
          - service_template: >
              {% if position > states.time_counter.tapparella_sala.state|int %}
                cover.open_cover
              {% elif position < states.time_counter.tapparella_sala.state|int %}
                cover.close_cover
              {% endif %}
            entity_id: cover.shelly_shsw_25_1103f6
          - service: time_counter.set
            entity_id: time_counter.tapparella_sala
            data_template:
              state: '{{ position }}'

@davanda try this:

Given you have cover.shelly_shsw_25 entity that allows cover.open_cover and cover.close_cover.

time_counter:
  cover_living_room:
    name: 'Living room cover timer'
    duration: 22

cover:
  - platform: template
    covers:
      living_room:
        friendly_name: 'Living room'
        close_cover:
          - service: cover.close_cover
            entity_id: cover.shelly_shsw_25
        open_cover:
          - service: cover.open_cover
            entity_id: cover.shelly_shsw_25
        stop_cover:
          - service: cover.stop_cover
            entity_id: cover.shelly_shsw_25
        position_template: '{{ (states.time_counter.cover_living_room.state|int) }}'
        set_cover_position:
          - service_template: >
              {% if position > states.cover.living_room.attributes.current_position|int %}
                cover.open_cover
              {% elif position < states.cover.living_room.attributes.current_position|int %}
                cover.close_cover
              {% endif %}
            entity_id: cover.living_room
          - service: time_counter.set
            entity_id: time_counter.cover_living_room
            data_template:
              state: '{{ position }}'

Then do not use cover.shelly_shsw_25 in your Lovelace, use only cover.living_room – with open/close/position.

Then you don’t need input_number in slider mode – use position in cover.living_room. It will start time_counter with time_counter.set service to given {{position}}. It will calculate time needed to move cover from current_position to position and send time_counter.stopped event – which with automations will set a cover in required position.

PS In this case you must also rewrite automations from cover.shelly_shsw_25 to cover.living_room.

1 Like

Perfect,
I used the code for configuration.yaml, but without changes in automations.yaml because cover.living_room always assumes the “open” state if set_position is > 0 and, therefore, the set_position value does not change.
Leaving the reference "cover.shelly_shsw_25 ONLY in automations.yaml, everything works fine.
Thanks a lot.

P.S.
Is there a way to reverse the state of the open / close label on the set_position slider?
When the value is 0% (= cover completely open), the control shows closed

Not sure. :slight_smile: Maybe simple try to change upcount with downcount and opposite. :slight_smile:

Great examples Seweryn,
I’d like to implement your time_counter into a command line cover.
this is the config of my cover:
how will I be able to implement this? Many thanks.

cover:
  - platform: command_line
    covers:
      markise:
        command_open: 'curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "UP" "http://192.168.1.59:8080/rest/items/OU_Terrace_Mark_oben_shutter"'
        command_close: 'curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "DOWN" "http://192.168.1.59:8080/rest/items/OU_Terrace_Mark_oben_shutter"'
        command_stop: 'curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "STOP" "http://192.168.1.59:8080/rest/items/OU_Terrace_Mark_oben_shutter"'
        command_state: "cat /config/states/coverstate.state"

command_state would then be replaced by the return of your time_counter.
your help is much appreciated.

Ralph