Automation Trigger: Putting Tablet in Wireless Charger

I currently use a button to trigger my TV Room to be set up when I’m done with dinner.

During dinner, I have my tablet sitting in a generic stand on the table to manage the music that’s being played, to follow the lyrics, etc.

What I want to achieve is the following:
When I move the tablet from the table into the charging stand, I want an existing script to be triggered - the one that I’m currently triggering by pushing a separate physical button. The script is all set up and working fine.

The tricky part is that when I put the tablet into the charger, the charger_type sensor changes to ‘wireless’ but it also does that every few minutes for a few seconds while the tablet is in the stand, so a simple to: wireless is not going to cut it. I need to filter out the cases where the sensor turns to wireless after it’s been on none for a few seconds.

Any idea how to template a filter that achieves that?

BTW:
Yes, there are other sensors, e.g. binary_sensor.drdashboard_is_charging, but they have the same issue.

You can add a Template condition to check that the previous state lasted for at least a specified amount if time:

- condition: template
  value_template: >-
    {% set previous = trigger.from_state.last_changed | as_datetime | as_local %}
    {{ now() - previous > timedelta(seconds=5) }}

This seems to work fine - thanks!
No way I would have figured that out on my own :frowning: