#Hi, I wonder if anybody can help me with
1 messages ยท Page 1 of 1 (latest)
I found it hard to understand the docs, so I cheated and sked ChatGPT and that worked after asking it to revise a few times.
- name: Media Player Paused State
state: >
{% if is_state('media_player.vardagsrum', 'paused') and
(as_timestamp(now()) - as_timestamp(states.media_player.vardagsrum.last_changed)) >= 5 %}
true
{% else %}
false
{% endif %}
```
that's still not going to work...
you can't use a normal template, it will not update when you want it to update.
You have to use a trigger based template sensor in order to achieve this.
chat GPT won't be able to help you because it learned HA before trigger based ttemplate entities existed.
but it does work. Maybe it has limitations, but right now I'm using it live
ofc if there is a "better" way I am open to learning that ๐
right, but the >= 5 will not work
that template will only update when media_player.vardagsrum changes state or once a minute on the minute
it will not resolve any other time
it has the exact same issue as what you were having issues with before.
YOu're welcome to argue all you want on this, but what I'm saying is 100% correct.
I have it set to >=20 now and it changed state after exactly 20 seconds. So it seems to work. Or am I missing something?
You are missing something
it will only update once a minute on the minute or when media_player.vardagsrum changes state
so that means, the template will only update when the minute crosses 0 seconds. or when media_player.vardagsrum changes state.
so you can be upwards of 40 seconds off.
if you're using 20 seconds as the >= number.
also, no amount of changes to that template will get you the results you want. You will need to use a trigger to force the updates of the template.
hmm sorry I'm really struggling to understand the issue, since it performs exactly as I wanted it to.
When media player is paused, and has been paused for 20 seconds, the state of my new sensor changes. Which is what I wanted.
and it's not doing that
which you're just simply ignoring
you think it's doing that, but it's not
Create the sensor, and use it without looking at the developer tools -> template result. You'll see what I mean.
so despite me sitting here counting the seconds after I press pause on the media_player, and despite the state in dev tool changing and the conditional cards updating....you are saying that this is not really happening.... ?
Yes
you finally understand
I'm telling you exactly how templates are designed
I helped design them, personally.
So I know what I'm talking about.
I'm using this to show different card in my dashboard. Which it does. How else can I prove that it it is/not is working?
there are 4 throttles for templates that are built into the system
I don't doubt your competence in this ๐
- Templates will only update when an internal sensor updates it's state or attributes.
- templates using
stateswill be throttled to at most 1 update per minute. - templates using
states.<domain>will be throttled to at most 1 update per second. - Templates using
now()ortoday_at()orrelative_time()will update once on the minute.
Your template is only using 1 and 4
so, it will 100% only update when media_player.vardagsrum changes state. And it will only update on the minute.
meaning any >= timing values will only be resolved on the minute
if your device changes state at 22 seconds past the minute, the next resolution will occur 38 seconds later.
i.e. it will not resolve 20 seconds later if you used >= 20
you're right. I tested again and it did not perform as ealier described. I must have pressed paused at some very particular time before then, since it worked twice....?
thanks for taking the time to explain a bit more. Hopefully I can get around to understanding the docs on this
@woeful totem this is what you need
template:
- trigger:
- platform: state
entity_id:
- media_player.vardagsrum
for:
hours: 0
minutes: 0
seconds: 5
id: "true"
to: paused
- platform: state
entity_id:
- media_player.vardagsrum
id: "2"
from: paused
sensor:
- name: Media Player Paused State
state: >
{%if(trigger.id == 'true')%}
true
{% else %}
false
{% endif %}
that's alittle verbose
template:
- trigger:
- platform: state
entity_id: media_player.vardagsrum
for: 5
id: "on"
to: paused
- platform: state
entity_id: media_player.vardagsrum
id: "off"
from: paused
binary_sensor:
- name: Media Player Paused State
state: "{{ trigger.id }}"
That's even better indeed
it should aslo be a binary_sensor
thank you! That looks very very similar to the yaml I saw whent rying to set this up as an automation instead. For the trigger that is. I will use that and deconstruct to learn exactly what is what. Thanks again!