Help with seconds counter if this is possible

Hi all
I have a cover that it is only report if it open – or closed.
I would like to have some kind of counter to count the seconds like below

when it is on open position it will show 0.
if I start to close the cover will start to count the seconds. for example 15 seconds
from position 15 seconds if I open the cover 10 seconds I would like to show 5. from here If I close the cover for 20 seconds the result should be 25.

everytime it goes to position close to show 100 and everytime it goes to position open to show 0.

Is that possible? If yes can someone give an example what I should do?

It won’t be 100% accurate but you could have an automation running every second using /1.
Then the choose action is opening or closing, and that leads to a set of input_number.

As I said it won’t be accurate since you could trigger the cover at some second with millisecond .001 so that the automation /1 has just passed.
But if the idea is just to get an rough idea of the position then I think it will be fine.

That’s the idea to get a rough estimation of their position. I am glad that potentially could work , now I need a little help with the action of the trigger if possible. I think I have to end up with 2 automations one if the state is opening and one if the state of the entity is closing, but I don’t know how to handle the action part in the code below. Can you give an idea?

- id: Tent position         
  alias: Tent position 

  trigger:
    - platform: time_pattern
      seconds: "/1"
  condition:
    condition: state
    entity_id: cover.50758014840d8e918614
    state: 'opening'

  action:

i think I need a counter (never used one before) like the below?

You stated it only reports open/closed but your State Condition checks for opening

    condition: state
    entity_id: cover.50758014840d8e918614
    state: 'opening'

So it also reports opening/closing?

yes, now I noticed that which is helpful.

I just wrote the below but haven’t test it yet

- id: Tent position opening       
  alias: Tent position opening

  trigger:
    - platform: time_pattern
      seconds: "/1"
  condition:
    condition: state
    entity_id: cover.50758014840d8e918614
    state: 'opening'

  action:
    - entity_id: counter.tent_count_seconds
      service: counter.increment
##################################################################     
- id: Tent position closing       
  alias: Tent position closing

  trigger:
    - platform: time_pattern
      seconds: "/1"
  condition:
    condition: state
    entity_id: cover.50758014840d8e918614
    state: 'closing'

  action:
    - entity_id: counter.tent_count_seconds
      service: counter.decrement

If it reports when it’s in the process of opening/closing then you can use that for triggering an automation (instead of employing a Time Pattern Trigger). In other words, the automation runs only when the cover is in motion.

The automation’s action can employ a repeat that increments or decrements the counter depending on whether it was triggered by closing or opening.


NOTE

The technique you are proposing, incrementing/decrementing a counter over a range of 100 (where 100 is closed and 0 is open) is based on a 1-second increment. That means it takes 100 seconds to increment the counter from 0 to 100. Unless your cover takes exactly 100 seconds to travel from closed to open, the counter will never accurately represent the cover’s true position.

I think something is strange with my covers. I recently add them with localtuya integration and thought their states are open-close, and just saw that they report opening and closing accordingly. But when they are completely opened they report opening too, and closing accordingly. I think I have to do something with the current position attribute.

My finally goal is to know what the tent position is in order to close it a little if the air is blowing strong

No you don’t need that.
You use choose and skip the condition.
Choose state = opening
action: increment

Choose state = closing
action: decrement

True.
But if it “calibrates” each time it hits open and closed and you fine tune number slightly what you should add/subtract then it could be a reasonable solution.

Based on the fact that Makis hasn’t yet fully characterized the cover’s state and attributes, I think it’s premature to predict the accuracy of this proposal.

The primary weakness of these proposals that attempt to infer a cover’s position based on timing (this isn’t the first instance I’ve seen here) is it gets derailed when the cover halts in mid-travel due to obstruction detection or mechanical failure. Unless the cover’s integration can report this failure mode, the counter continues merrily incrementing/decrementing while the cover is no longer actually moving.

One mitigation technique is to employ a timer and if the door fails to open/close within the normal duration, the failure is reported.

I think will never know if it could somehow work or not. I see now that during the opening or the closing of the cover the current_position remains at 1 or 2 value. Only if I manually stop the cover somewhere in the middle it reports 3 (open).

This is what they do:
if the are closed and I press the button (physically or in HA or with automation) to completely open them they are reporting “opening”. After a few seconds when they are completely opened I can listen a tick sound from their physical switch and their light goes from red to blue.
Unfortunately they still report ‘opening’ and not open for example and current position :1
If I press the stop button before the tick sound of their switch even if they are completely opened they report open and current position: 2

From what I am seeing there is no way to determine when they are opening or closing in order to count the seconds to have an estimation of their position. So I think it would be better to give up at least for now.