Trying to set up an automation for closing blinds

Hello, i have got a lot of things working now.
I have window blinds tilt to close automatically when sun sets and open when sun rises.
I have a Bruh multi-sensor up and running.
Now i want to create an automation based on a lux value for the blinds to close and open.

But here is a catch. I don’t want to open the blinds when for instance a cloud goes over.
Because that could cause erratic behavior of the blinds.

The blinds need to close at lets say 900 lux but when a cloud comes the value will drop below that.
I want the blinds to stay closed for about 10 minutes. after it dropped below 900.
But if it goes over the 900 again the timer should stop, and only start counting again until it goes below 900 again.

This will prevent erratic behavior.
Only thing is that i have o clue on how to realize this, or if it is even doable.

My blinds function as light switches, on and of mode.

Thanks,
Arnold

1 Like

Might be more work then its worth but I would set up a 2ed Lux sensor in another room and have the blinds open and close biased on a average, I’m doing the same right now on temperature sensors and a window AC unit

Or perhaps in a automation set the trigger at the lux you want then in the conditions set a delay of one or two minutes then check the lux again to see if its still low then proceed with the closing of the blinds. The Delay should give enough time for the cloud to pass before closing the blind.

Maybe something like this:

automation:
  trigger:
    - platform: numeric_state
      entity_id: sensor.bruh
      below: 900
      for:
        minutes: 10
    - platform: numeric_state
      entity_id: sensor.bruh
      above: 899
      for:
        minutes: 10
  action:
    service_template: >
      {% if states("sensor.bruh")|int < 900 %}
        homeassistant.turn_on
      {% else %}
        homeassistant.turn_off
      {% endif %}
    entity_id: switch.my_blinds

Obviously I don’t know the exact names of your entities, and I might have gotten open & close backwards (again, not knowing your specifics), but the general idea is, trigger the automation whenever the illuminance drops below 900, and stays that way for at least ten minutes (or use whatever time period you want), or raises to or above 900, and stays that way for the desired amount of time.

BTW, you might need some hysteresis to prevent the blinds going up and down because closing them makes the room darker, and opening them makes the room lighter, which could cause the sensor value to go back and forth across the one threshold (of 900.) I.e., you might need some separation between the below and above numbers (maybe below: 900 and above: 1500 or something depending on the sensitivity and resolution of your illuminance sensor.)

Thanks, this looks promising, i am going to try this and let you know how it works.
I have the sensor sitting between the blinds and the window, so the sun will keep shining on it even when the blinds tilt to close.

1 Like

BTW, what I suggested effectively “filters out” short lux changes. Or to put that another way, effectively delays the response to lux changes. This, of course, is not what you originally asked for, but might be the better approach.

If you’d rather have the blinds change immediately, but want to implement a minimum period for staying in each state, that is also possible. (In fact, I do that with some lights I automate.) If you’d rather do that, let me know and I could make a different suggestion.

Oh, what the heck, here is how I do it for the lights on the front of my house. Oh, and BTW, sensor.illuminance is not a real light sensor. It’s a custom component I added that estimates outdoor illuminance based on the current weather conditions as reported by Weather Underground. :slight_smile: And the DELAYED_HOMEASSISTANT_START part is to make sure that if I’ve had HA down for a while for some reason, or maybe power went our for a while, when it comes back up the lights will be set to what they should be (as if HA was running the whole time.)

- alias: Delayed Startup
  trigger:
    platform: homeassistant
    event: start
  action:
    - delay: 00:00:15
    - event: DELAYED_HOMEASSISTANT_START

# House Front based on:
# - Illuminance
# - Home Assistant start
- alias: House Front
  trigger:
    - platform: numeric_state
      entity_id: sensor.illuminance
      above: 999
    - platform: numeric_state
      entity_id: sensor.illuminance
      below: 1000
    - platform: state
      entity_id: switch.house_front_lights
      to: 'on'
      for:
        minutes: 30
    - platform: state
      entity_id: switch.house_front_lights
      to: 'off'
      for:
        minutes: 30
    - platform: event
      event_type: DELAYED_HOMEASSISTANT_START
  condition:
    condition: template
    value_template: >
      {% if trigger.platform == "event" %}
        true
      {% else %}
        {{ as_timestamp(now()) - as_timestamp(states.switch.house_front_lights.last_changed) > 30*60 }}
      {% endif %}
  action:
    service_template: >
      {% if states("sensor.illuminance")|int >= 1000 %}
        switch.turn_off
      {% else %}
        switch.turn_on
      {% endif %}
    entity_id: switch.house_front_lights

This is exactly how i wish it should behave.
I am trying to set this op at this moment but i get an error.

Invalid config for [automation]: extra keys not allowed @ data[‘trigger’][0][‘minutes’]. Got None
offset None should be format ‘HH:MM’ or ‘HH:MM:SS’ for dictionary value @ data[‘trigger’][0][‘for’]. Got None. (See /config/configuration.yaml, line 117). Please check the docs at https://home-assistant.io/components/automation/

You might have the indentation wrong. Can you post exactly what you have?

I have got it, the configuration check is okay (its those spaces)

1 Like

I think it works although i have to play with the values a bit.
This is my code now.

- alias: 'Set blinds on sunlight'
  trigger:
    - platform: numeric_state
      entity_id: sensor.sn2_ldr
      below: 900
      for:
        minutes: 10
    - platform: numeric_state
      entity_id: sensor.sn2_ldr
      above: 899
      for:
        minutes: 10
  action:
    service_template: >
      {% if states("sensor.sn2_ldr")|int < 900 %}
        light.turn_off
      {% else %}
        light.turn_on
      {% endif %}
    entity_id: light.blind3

But i cant figure out why the values have to be like this.
below 900
above 899

Shouldn’t that be the other way around like?
above 900
below 899

also this line

  {% if states("sensor.sn2_ldr")|int < 900 %}

I think this means that if the value is below 900, but what does the % mean.
That is my question also for the lines following beneath that line.

It depends what you’re trying to do. Assuming sensor.sn2_ldr only takes on integer values, then below: 900 and above: 899 effectively implements a single threshold. The automation will trigger whenever the value goes from 900 → 899 (because it went below 900) or from 899 → 900 (because it went above 899.) The threshold is effectively between 899 & 900.

If you were to use above: 900 and below: 899, then you would be implementing hysteresis. That is, the automation would trigger if the value of sensor.sn2_ldr went from 900 → 901, but then when it drops, it wouldn’t trigger until the value went from 899 → 898. (Same situation for the reverse scenario.) So the threshold for a rising value would be different than the threshold for a dropping value.

Yes, that’s correct. See:

Normally i just lookup to what i need in the forums and that’s how i build my Home Assistant for over the past 2 years now.
Thinking about doing something back to the ha community i share my code here.

I was looking at this post for a while and yesterday i installed the KAKU Asun 650 blinds controller.
Now i already made some nice Bruh’s Multisensors also and was looking for a way to automate and mix them together.

I want to thank everybody in this post for helping me out. :wink: And i want to share my mixed configuration, that i have at the moment.

Here’s my config:

Sunrise:

  • alias: Bij opkomende zon, zolder scherm naar beneden.
    hide_entity: True
    trigger:
    platform: numeric_state
    entity_id: sensor.sn2_ldr
    above: 899
    for:
    minutes: 10
    condition:
    • condition: state
      entity_id: switch.zolderscherm
      state: ‘on’
    • condition: numeric_state
      entity_id: sun.sun
      value_template: ‘{{ state.attributes.elevation }}’
      above: -3.5
      action:
    • service: homeassistant.turn_off
      entity_id: switch.zolderscherm
    • service: tts.google_say
      entity_id: media_player.ok_google_media
      data_template:
      message: " Het zonnescherm op zolder is omlaag. "
      language: ‘nl’
    • service: notify.telegram
      data:
      message: Het zonnescherm op zolder is omlaag.

and for the sunsets:

  • alias: Bij ondergaande zon, zolder scherm omhoog.
    hide_entity: True
    trigger:
    platform: numeric_state
    entity_id: sensor.sn2_ldr
    below: 654
    for:
    minutes: 5
    condition:
    • condition: state
      entity_id: switch.zolderscherm
      state: ‘off’
    • condition: numeric_state
      entity_id: sun.sun
      value_template: ‘{{ state.attributes.elevation }}’
      below: 9.5
      action:
    • service: homeassistant.turn_on
      entity_id: switch.zolderscherm
    • service: tts.google_say
      entity_id: media_player.ok_google_media
      data_template:
      message: " Het zonnescherm op zolder is omhoog. "
      language: ‘nl’
    • service: notify.telegram
      data:
      message: Het zonnescherm op zolder is omhoog.

Sorry :slightly_frowning_face: for my bad code copy and pasting in here.
I’m still learning.

Great to see how someone else approaches this.
I am wondering how your light sensor works.
My problem is that mine registers the highest value of around 970.
It starts at that value at around 8 am these days and keeps that until 7 pm.
Only thing is that the sun stops shining at that window around 1 pm.
Normally i should see a lower value when there is no direct sunlight on the sensor i would think.

I think i need a sensor that can read much higher lux values.

Do you have google Home pronounce the message?

Thanks tor the message back 2stimpy

I don’t have a lot of time at the moment, but I’m rebuilding the code a little for exactly the same thing you have.

At now the blinds will close when the sun comes up at a certain time. I am too struggling with the exact time of opening them again, when my upstairs spot is sun free at around 6 p.m. I will be back in a short period of days when I have right automation running.

About the Google pronouncing message…
It’s fairly easy to do and setup,
check…

If you need any help setting it up, let me know :wink: