[SOLVED] State of sensor, enable/disable roller shutter

So, here’s the case!

I have a balcony door, which has a door sensor attached to it. The doors open inwards. At the same door I have a roller shutter.

How do I prohibit the roller shutter from going down if the door is open?

The thing is that the roller shutter is in an automation and sometimes I forget to close the door…and well…yeah…that sucks!

Sure, I can put a condition in the automation, but what about the “roller shutter switch” itself, I sometimes just tell Google Assistant to close it and then if the door is open…well, yeah, sucks again.

Thankful for any help :slight_smile:

I suggest the switch is directly connected to the shutter (so it is possible to control the shutter even if HA is not running)? so, it its kind of impossible for HA to supress the control from the switch.
The only thing I can imagine is to create an automation which is triggered, when the shutter is controled, then checks the state of the door, and if it is open, open the shutter again. Then it depends on how fast it reacts, if you recognize this or not…

No, I mean the switch in HA, there is no physical switch at all!

Ah, okay, i missunderstood…
But then it should be possible. Didn’t think it through completely, but the idea is to create a template cover entity, which you can use in your Lovelace GUI instead of the normal cover entity. All actions defined in the template cover can be directed to a script, which checks the door first and then calls the service on the real cover.
Here are some helpful links:


Thanks, I got it somehow working, but not entirely!

I got the template cover to check if the door is open, if it is, it doesn’t close the cover it if is indeed closed it closes the cover.

However, the position or state of the template cover doesn’t change to reflect the real covers position and/or state.

I’ve fiddled around with value_templates, but now I’ve ran out of ideas to try.

My two covers below and there states…the cover is closed, but the template one remains open…

cover.shutter_278	closed	
current_position: 0
Vera Device Id: 278
friendly_name: Rullgardin
supported_features: 15
cover.sovrummet_rullgardin	open	
friendly_name: Rullgardin
supported_features: 11

The script for opening the cover…

I’ve tried to remove the conditions aswell, but it didn’t make any difference…I’ve also tried without the value template and instead use the state of the cover, which should be the same, but no difference.

oppna_rullgardin:
  alias: Öppna rullgardin
  sequence:
  - condition: and
    conditions:
    - condition: state
      entity_id: sensor.lilla_balkongen_dorr
      state: 'Stängd'
    - condition: template
      value_template: "{{ is_state('cover.shutter_278', 'closed') }}"
  - service: cover.open_cover
    entity_id: cover.shutter_278

I’ve also tried some variations of the following:

value_template: "{{ state_attr('cover.shutter_278', 'current_position') > 0 }}"

Can you post the entire template cover that you are using?

Took the example from https://www.home-assistant.io/integrations/cover.template/ and changed it a little!

# Rullgardin
cover:
  - platform: template
    covers:
      sovrummet_rullgardin:
        friendly_name: "Rullgardin"
        position_template: "{{ is_state('cover.shutter_278', 'open') }}"
        open_cover:
          service: script.oppna_rullgardin
        close_cover:
          service: script.stang_rullgardin
        stop_cover:
          service: script.stoppa_rullgardin

change position_template to value_template

Thanks, that solved it, partly!

However…if I stop the cover at, let’s say 50%, doesn’t matter if it is from open or closed state, the “up-button” gets greyed out, also, there is no slider to set the position.

I guess you should somehow manage to get the current_position from the real cover.

Well this is when things get tricky, does your other cover support position, etc?

Yeah, it does!

I can use the original slider or tell Google to set it at x %!

So then all you need to do is extend the functionality to this one.

cover:
  - platform: template
    covers:
      sovrummet_rullgardin:
        friendly_name: "Rullgardin"
        value_template: "{{ is_state('cover.shutter_278', 'open') }}"
        position_template: "{{ state_attr('cover.shutter_278', 'position') }}"
        set_cover_position:
          service: cover.set_position
          data_template:
            entity_id: cover.shutter_278
            position: "{{ position }}"
        open_cover:
          service: script.oppna_rullgardin
        close_cover:
          service: script.stang_rullgardin
        stop_cover:
          service: script.stoppa_rullgardin

But you’ll have to make a script if you want to stop the action of moving when the door is open.

rullgardin_set_cover_position:
  alias: Öppna rullgardin
  sequence:
  - condition: and
    conditions:
    - condition: state
      entity_id: sensor.lilla_balkongen_dorr
      state: 'Stängd'
    - condition: template
      value_template: "{{ is_state('cover.shutter_278', 'closed') }}"
  - service: cover.set_position
    data_template:
      entity_id: cover.shutter_278
      position: "{{ position }}"
cover:
  - platform: template
    covers:
      sovrummet_rullgardin:
        friendly_name: "Rullgardin"
        value_template: "{{ is_state('cover.shutter_278', 'open') }}"
        position_template: "{{ state_attr('cover.shutter_278', 'position') }}"
        set_cover_position:
          service: script.rullgardin_set_cover_position
          data_template:
            position: "{{ position }}"
        open_cover:
          service: script.oppna_rullgardin
        close_cover:
          service: script.stang_rullgardin
        stop_cover:
          service: script.stoppa_rullgardin

I got some error, with that template…

Invalid config for [cover.template]: two or more values in the same group of exclusion 'value_or_position' @ data['covers']['sovrummet_rullgardin'][<value_or_position>]. Got None. (See ?, line ?). 

Then remove the value_template all together.

Okay, so now it validates…and the slider shows up…but still the slider doesn’t work, neither the “up-button” if stopped before it’s totally closed.

My cover has the attribute below, should we maybe, somehow, use that instead?

current_position

ah yes, use that in this template instead of 'position'

        position_template: "{{ state_attr('cover.shutter_278', 'current_position') }}"

You may need to verify that set_position takes the variables I used. I"m going off the top of my head here.

So the template cover gets the value of current_position from the real cover, but not the other way around when dragging the slider.

I’ve tried putting current_position in various places to no luck…

Damn, that this was going to be an easy thing to do :grin:

From the docs I would suggest you have to do it like this:

set_cover_position:
  service: script.rullgardin_set_cover_position
  data:
    position: "{{position}}"

It’s data instead of data_template.

That’s only in version 0.115 and data_template still works. That will have no impact on the behavior.

Can you take a screenshot of the cover.shutter_278 in your developer tools -> states page? Make sure to include all the attributes.