Hi there
I’m using the Motionblinds integration but by design, the Motionblind cover motors via the bridge do not report opening/closing states. But they do report the current position of the cover/blinds. (Specifically, I’m using the CMD-01 bridge with the CMD-02-P motor).
I was surprised that I could not find a template cover for Motionblinds already in this forum, thus I share it here for others.
I created a template sensor and with that, a cover template which will then include the opening/closing states.
- When opening / closing, the current position is reported for ~5 seconds, seldomly for ~6 seconds before that value is again updated. I gave it 7 seconds to be safe
- service calls from the dashboard entity card are slightly differently formatted compared to service calls from the dev-tools, which is respected by the sensor
- Instant state changes when the fully-open / fully-closed position is reached (no waiting for 7 seconds to get the updated state)
- If covers are open already but the service open_cover is called, the state remains open
- The same goes for closed state
I have been using it for a while and it works like a charm. If the service-calls would be equal when fired from the dashboard and from the dev-tools, the sensor-triggers could be cut in half. (Suggestions welcome )
First, create a template sensor in the configuration.yaml. For the entity-id, use your existing cover-name (from the Motionblinds Integration):
template:
- trigger:
- platform: event
event_type: call_service
event_data:
service: set_cover_position
service_data:
entity_id:
- cover.blinds_kitchen
id: "set-position"
- platform: event
event_type: call_service
event_data:
service: set_cover_position
service_data:
entity_id: cover.blinds_kitchen
id: "set-position"
- platform: event
event_type: call_service
event_data:
service: close_cover
service_data:
entity_id:
- cover.blinds_kitchen
id: "closing-cover"
- platform: event
event_type: call_service
event_data:
service: close_cover
service_data:
entity_id: cover.blinds_kitchen
id: "closing-cover"
- platform: event
event_type: call_service
event_data:
service: open_cover
service_data:
entity_id: cover.blinds_kitchen
id: "opening-cover"
- platform: event
event_type: call_service
event_data:
service: open_cover
service_data:
entity_id:
- cover.blinds_kitchen
id: "opening-cover"
- platform: event
event_type: call_service
event_data:
service: stop_cover
service_data:
entity_id:
- cover.blinds_kitchen
id: "stop-cover"
- platform: event
event_type: call_service
event_data:
service: stop_cover
service_data:
entity_id: cover.blinds_kitchen
id: "stop-cover"
- platform: state
entity_id:
- cover.blinds_kitchen
attribute: current_position
for:
seconds: 7
id: "current-position"
- platform: numeric_state
entity_id:
- cover.blinds_kitchen
attribute: current_position
above: 99
id: "current-position"
- platform: numeric_state
entity_id:
- cover.blinds_kitchen
attribute: current_position
below: 1
id: "current-position"
sensor:
- name: Blinds Kitchen State
icon: mdi:blinds
state: >
{% set entity = 'cover.blinds_kitchen' %}
{% if (trigger.id == 'set-position' and (state_attr(entity, 'current_position') - trigger.event.data.service_data.position > 0)) %}
closing
{% elif (trigger.id == 'closing-cover') %}
{{ 'close' if state_attr(entity, 'current_position') == 0 else 'closing' }}
{% elif (trigger.id == 'set-position' and (state_attr(entity, 'current_position') - trigger.event.data.service_data.position < 0)) %}
opening
{% elif (trigger.id == 'opening-cover') %}
{{ 'open' if state_attr(entity, 'current_position') == 100 else 'opening' }}
{% elif (trigger.id == 'stop-cover' or trigger.id == 'current-position') %}
{{ 'open' if state_attr(entity, 'current_position') > 0 else 'closed' }}
{% else %}
unknown
{% endif %}
Second, create the cover template in the configuration.yaml. For the entity-id, use your existing cover-name (from the Motionblinds Integration) and for the sensor, use the sensor-entity you created above:
cover:
- platform: template
covers:
blinds_kitchen_mod:
device_class: shade
friendly_name: "Blinds Kitchen Mod"
position_template: "{{ state_attr('cover.blinds_kitchen', 'current_position') }}"
value_template: "{{ states('sensor.blinds_kitchen_state') }}"
open_cover:
action: cover.open_cover
entity_id: cover.blinds_kitchen
close_cover:
action: cover.close_cover
entity_id: cover.blinds_kitchen
stop_cover:
action: cover.stop_cover
entity_id: cover.blinds_kitchen
set_cover_position:
action: cover.set_cover_position
entity_id: cover.blinds_kitchen
data:
position: "{{position}}"
Third, in the dev tools reload the config (template-entities) and the sensor and template-cover will be created.