trying to create a binary_sensor for a cover to indicate it is currently changing position.
Im stuck though…
this is a the template for current position:
I think it would be needed to compare current position with position of now() - (now()+1).
or could I simply check for last_changed (which changes on all attributes changes too)
if stopped, and again changing position, the last changed remains the same… it only changes when state changes from open to closed, not even vice versa ??
Hey Marius, can you provide a little more detail as to which cover(s) you’re using?
Most of the covers have a “closing” and “opening” state while moving, can you check if yours does as well? The Icon for the cover will change in the UI to an arrow pointing up-/downwards.
Yes, I also have the IKEA covers, do you use ZHA, their gateway or Deconz?
I’m using ZHA for them - don’t know what you’re trying to achieve, but I set up an automation that triggers an update_entity service call on the cover whenever its state gets updated, so it won’t be stuck at “closing”.
Checked out the other IKEA blind on the Tradfri Gateway, you’re right, they don’t report opening/closing.
In that case I’d create two “Trend” sensors: https://www.home-assistant.io/integrations/trend
One for opening, one for closing. Have the icon_template (not icon) reflect the value of the new binary sensors
thanks! will probably do the trick this needs some more attention, because both binaries show off all the time, and dont respond at all (wait, restart… had the wrong entity_id…)
Ok, so the entity_id helped still not perfect though, because it only works when moving, and doesnt stop when the cover is either stopped manually, or because it reached its objective postition.
Do I need to set anything else in the sensor configs? Maybe the sample_duration? Nope, tried that, results are still the same: only starting a motion changes the binary trend sensor… min_gradient is too unreliable to use.
Even if this did the trick though, I feel we would need the attribute in the cover entity_id directly. Hope this can be PR or FR’d to the Ikea integration, will have a look to contact the author.
Also, I don’t understand the absence of response checking the last_changed, and more than that, it is only changing in 1 direction… must be a bug?
small update for the night:
this automation does work triggering on state (which is also triggered by the attributes changes, as I hoped in my first post)
automation:
alias: Cover is moving
trigger:
platform: state
entity_id: cover.raamverduistering_stookhok
action:
service: notify.system
data_template:
title: Cover is moving
message: current position is {{trigger.to_state.attributes.current_position}}
It even triggers more than once per second so it seems…:
had to get back to my first thought, an automation triggering on the state (which also triggers on each attribute change) of the cover. Use that in a template for a binary sensor… very convoluted, especially since the automation shouldn’t do anything, only trigger…
had to use an empty script, with a delay of a second (and use the upcoming mode: parallel I have been testing lately, so dont yet try this before it is released) because without the delay in the script, the automation wouldn’t set it’s last_triggered attribute:
automation:
alias: Cover stookhok is moving
trigger:
platform: state
entity_id: cover.raamverduistering_stookhok
action:
service: script.trigger_only
and script:
trigger_only:
alias: Trigger only
mode: parallel
sequence:
delay:
seconds: 1
homeassistant:
customize:
cover.raamverduistering_stookhok:
templates:
icon: >
if (entities['binary_sensor.raamverduistering_stookhok_moving'].state == 'on') return 'mdi:animation';
if (state == 'open' && attributes.current_position == 100) return 'mdi:window-shutter-open';
if (state == 'closed') return 'mdi:window-shutter';
else return 'mdi:window-shutter-alert';
icon_color: >
if (entities['binary_sensor.raamverduistering_stookhok_moving'].state == 'on') return 'red';
if (state == 'open' && attributes.current_position == 100) return 'gold';
if (state == 'closed') return 'darkblue';
else return 'green';
consuming all of this, made me decide to file a bug report on the missing attributes ‘opening’ and ‘closing’ after all. Really feels like it should have been there in the first place. https://github.com/home-assistant/core/issues/37223
having consumed very useful advise from Phil, (making this really his solution, but cant cross thread a solution mark I think?) the setup has advanced, please see Automation issue: why isn't this wait_template waiting to avoid crossposting the same code.
Finally I have found a way to not only indicate the covers are moving, but also in which direction
Now let’s hope the FR will at all be considered, cause this should really all be unnecessary, and in the core code for the Ikea Tradfri covers…