#Transition state of projector
1 messages · Page 1 of 1 (latest)
This now always shows a state of "unknown" whenever it is in transition. I tried some similar approaches without success. I'm starting to think you cannot make use the value of the entity you are trying update in the template. Maybe some self referencing/blocking issue? I've also tried using a variable and assigning the previous state with similar issues. I'm stumped.
Actually looking at the last attempt, the third line will always be true if the first 2 lines are false.
no
you need the current state to be either on or off to know if you should evaluate to shutting down or starting up. So if it is something else, like unavailable or unknown the template has no clue to which transition state it should go
That's why I put that in
The idea is that as soon as the power usage is between the 2 values, the template is evaluated, and then uses the current state
current state being the old one
so that one has to be on or off
you can try a trigger based template sensor
I'm following the logic but it's not working out that way. Always shows unknown when in transition either way. I'm learning quite a bit so far anyway - appreciate it.
I need to look into a trigger based template as I'm not familiar with it
template:
- trigger:
- platform: numeric_state
entity_id: sensor.projector_checker_current_consumption
above: 260
id: "on"
- platform: numeric_state
entity_id: sensor.projector_checker_current_consumption
below: 1
id: "off"
- platform: numeric_state
entity_id: sensor.projector_checker_current_consumption
above: 1
id: "starting up"
- platform: numeric_state
entity_id: sensor.projector_checker_current_consumption
below: 260
id: "shutting down"
sensor:
- unique_id: some_unique_id
name: Some name
state: "{{ trigger.id }}"
Wow! you are quick. I'll try this.
Maybe better to do it differently though
template:
- trigger:
- platform: state
entity_id: sensor.projector_checker_current_consumption
to: ~
sensor:
- unique_id: some_unique_id
name: Some name
state: >
{% set from = trigger.from_state.state | float('no number') %}
{% set to = trigger.to_state.state | float('no number') %}
{% set number = from | is_number and to | is_number }}
{% if to | is_number and to > 260 %}
on
{% elif to | is_number and to < 1 %}
off
{% elif number and to > from %}
warming up
{% elif number and to < from %}
shutting down
{% else %}
unknown
{% endif %}
Have just tried the first version of the trigger template and it works! (indent of sensor: was slightly off)
It takes me a while to test because projector starting and stopping is slow
Initial value was unknown when I reloaded the template so I assume will be unknown after reboot
The second one updates more (on every state change)
But after a reboot it will get the previous state (as of 2022.5)
I'm struggling to understand the second one. Will have to take some time to study it. The first one I understand. I'm on 2022.5
The second one triggers on every state change of your consumption sensor
and then compares the previous value with the new value
Using variables?
OK I've got it now. I'll have a play with it tomorrow. I can use this elsewhere too. Thanks so much for your help in making the world a smarter place.
Adjusted the template above
in the previous version it would show unknown after reboot, even if the projector was on or off, now it won't
Although does this rely on the power usage being constantly increasing or decreasing to determine warming up or shutting down?
I'd have to monitor it to see if this is the case. I'm pretty sure that during start up, the power goes up and down.
I would assume so, as the lamp is the main cause of power usage, and that one is heating up, so using more and more power
But if that is not the case, the other version might be better
There was an error - }} instead of %} on third line of state section
As I feared , the state toggles between starting and warming due to fluctuations in the power draw during start up and shut down. This will mess up my automations. I will use the first version instead
I must admit, I don't fully understand the logic of the first method - although it seem to work. During start up and shutdown, both the third and fourth triggers are true so how does it select one over the other?