Shutters automation with luminance sensor

Hi HA enthusiasts and gurus!
I wanted to share my attempt to automate external horizontal shutters


based on luminance sensor. I have them controlled by Shelly 2.5 which after calibration enable to set a % position. I have also created 4 scripts to set them in slightly open at 1, 2, 3 and 4% (to achieve that the shutter has to close completely and open to the desired percentage):

cover_open_1:
  alias: Shutters 1%
  sequence:
  - service: cover.set_cover_position
    data:
      entity_id: cover.shellyswitch25_483fda821821
      position: 0
  - wait_template: '{{ is_state(''cover.shellyswitch25_483fda821821'', ''closed'')
      }}'
    timeout: 00:01:00
  - service: cover.set_cover_position
    data:
      entity_id: cover.shellyswitch25_483fda821821
      position: 1
cover_open_2:
  alias: Shutters 2%
  sequence:
  - service: cover.set_cover_position
    data:
      entity_id: cover.shellyswitch25_483fda821821
      position: 0
  - wait_template: '{{ is_state(''cover.shellyswitch25_483fda821821'', ''closed'')
      }}'
    timeout: 00:01:00
  - service: cover.set_cover_position
    data:
      entity_id: cover.shellyswitch25_483fda821821
      position: 2
cover_open_3:
  alias: Shutters 3%
  sequence:
  - service: cover.set_cover_position
    data:
      entity_id: cover.shellyswitch25_483fda821821
      position: 0
  - wait_template: '{{ is_state(''cover.shellyswitch25_483fda821821'', ''closed'')
      }}'
    timeout: 00:01:00
  - service: cover.set_cover_position
    data:
      entity_id: cover.shellyswitch25_483fda821821
      position: 3
cover_open_4:
  alias: Shutters 4%
  sequence:
  - service: cover.set_cover_position
    data:
      entity_id: cover.shellyswitch25_483fda821821
      position: 0
  - wait_template: '{{ is_state(''cover.shellyswitch25_483fda821821'', ''closed'')
      }}'
    timeout: 00:01:00
  - service: cover.set_cover_position
    data:
      entity_id: cover.shellyswitch25_483fda821821
      position: 4

now I’ve put a Xiaomi Luminance sensor on the desk just in front of the window in an attempt to control the position of the shutter depending on the luminance measured:

- id: '1614674730761'
  alias: Shutter - above 1400lx
  trigger:
  - platform: numeric_state
    entity_id: sensor.xiaomi_lumi_sen_ill_mgl01_illuminance
    above: '1400'
  condition:
  - condition: numeric_state
    entity_id: cover.shellyswitch25_483fda821821
    attribute: current_position
    above: '1'
  - condition: state
    entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_on_off
    state: 'off'
  action:
  - service: script.cover_open_1
    data: {}
  mode: single
- id: '1614675625938'
  alias: Shutter - below 500lx
  trigger:
  - platform: numeric_state
    entity_id: sensor.xiaomi_lumi_sen_ill_mgl01_illuminance
    below: '500'
  condition:
  - condition: state
    entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_on_off
    state: 'off'
  action:
  - choose:
    - conditions:
      - condition: numeric_state
        entity_id: cover.shellyswitch25_483fda821821
        attribute: current_position
        above: '0'
        below: '2'
      sequence:
      - service: script.cover_open_2
        data: {}
    - conditions:
      - condition: numeric_state
        entity_id: cover.shellyswitch25_483fda821821
        attribute: current_position
        above: '1'
        below: '3'
      sequence:
      - service: script.cover_open_3
        data: {}
    - conditions:
      - condition: numeric_state
        entity_id: cover.shellyswitch25_483fda821821
        attribute: current_position
        above: '2'
        below: '4'
      sequence:
      - service: script.cover_open_4
        data: {}
    default: []
  mode: single

Overall, it works well, there are times though when it is frequently opening and closing.This is at times when the sun is covered by clouds and the clouds are on and off. The luminance values were defined experimentally in full sunshine and work well also when the sun is behind the clouds. What would you recommend doing to avoid too frequent opening and closing of the shutters?

I don’t use the light sensor directly, but a filtered version of it like this:

  - platform: filter
    name: "Lysstyrke filtrert"
    entity_id: sensor.ute_lysstyrke
    filters:
      - filter: lowpass
        time_constant: 10
        precision: 1
1 Like

Oh, I never used the filter platform. Need to learn more about it, thanks! Most likely I would keep the high luminance trigger as I would prefer to close the shutters when the sun beams hit the desk straight (especially important in the work from home times - maybe I will make it dependant on the work laptop presence?).

You could create a third sensor which is the max out of the light sensor and the filtered light sensor :wink:

1 Like

Experimenting with the filtered sensor now. For the high luminance I have made the automation dependant on if a work laptop is on or not. Let’s see how that works tomorrow as sun is out of sight for today. Many thanks @stigvi for suggestions and inspiration!

There is a lot of little things to do. On my curtains I have:

  • Filtered light sensor
  • A countdown timer so that when they go down, they stay down for some time
  • Checking the weather forecast and if it is no clouds, the filtered light sensor is bypassed
1 Like

Yeah, some of it I already have - they only work up and down if the window is closed, they close partially early in the morning only if the weather is sunny or partly cloudy etc :slight_smile: Possibilities are endless… The key is to find a good balance between being happy with the automation behaviour and the complexity of the automation.

1 Like

I’ve used an interior and exterior light sensors to govern when certain things should happen (such as when interior lights should be turned on and off). To prevent erratic behavior, I also filter the sensor values. You can see the difference between the filtered/unfiltered values here:

Screenshot from 2021-03-09 08-11-25

The desired amount of filtering was achieved after some experimentation. After trying a few combinations of filters, I settled on using a simple low-pass filter like this:

- platform: filter
  name: "Patio Luminance Filtered"
  entity_id: sensor.patio_luminance
  filters:
  - filter: lowpass
    time_constant: 5
    precision: 0
1 Like