Cloud cover trigger - not sure how best to write this trigger up

The goal is to add on the fly adjustments to the lights based upon changes in cloud cover. It works great as a condition when the lights are off. But, my problem these days with a sick kid at home (Covid fun when it’s supposedly over…yay) is that constant movement means lights are always on. So, they do not end up adjusting to the outdoor light change.

I recognize this isn’t the best but it’s what I have to work with at the moment. Sometime I’ll look into spending dinero I don’t have for ambient light sensors.

The trigger I came up with is:

  trigger:
  - type: cloudcover
    platform: device
    device_id: 45a6ae64e81ca2ca86450430756e47f8
    entity_id: sensor.openweathermap_cloud_coverage
    domain: sensor
    above: 49
    below: 101
    for:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0

The below/above adjustments are odd I grant you. I am using -1 and 101 because cloud cover can be 0 and can be 100.

I wrote the YAMLs as follows:

- id: '331899958999004'
  alias: Kitchen lights on with no cloud cover already on adjustment
  trigger:
  - type: cloudcover
    platform: device
    device_id: 45a6ae64e81ca2ca86450430756e47f8
    entity_id: sensor.openweathermap_cloud_coverage
    domain: sensor
    above: -1
    below: 20
    for:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  condition:
  - condition: and
    conditions:
    - condition: sun
      before: sunset
      before_offset: -01:30:01
    - condition: time
      after: 09:00
  action:
  - service: light.turn_on
    target:
      entity_id: light.kitchen_main_lights
    data:
      brightness_pct: 0
  - service: light.turn_on
    target:
      entity_id: light.kitchen_under_cabinet
    data:
      brightness_pct: 30
  - service: switch.turn_off
    target:
      entity_id: switch.kitchen_sink_light


- id: '331899958999003'
  alias: Kitchen lights on with lots of cloud cover already on adjustment
  trigger:
  - type: cloudcover
    platform: device
    device_id: 45a6ae64e81ca2ca86450430756e47f8
    entity_id: sensor.openweathermap_cloud_coverage
    domain: sensor
    above: 49
    below: 101
    for:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  condition:
  - condition: and
    conditions:
    - condition: sun
      before: sunset
      before_offset: -01:30:01
    - condition: time
      after: 09:00
  action:
  - service: light.turn_on
    target:
      entity_id: light.kitchen_main_lights
    data:
      brightness_pct: 50
  - service: light.turn_on
    target:
      entity_id: light.kitchen_under_cabinet
    data:
      brightness_pct: 70
  - service: switch.turn_off
    target:
      entity_id: switch.kitchen_sink_light


- id: '331899958999001'
  alias: Kitchen lights on with some cloud cover already on adjustment
  trigger:
  - type: cloudcover
    platform: device
    device_id: 45a6ae64e81ca2ca86450430756e47f8
    entity_id: sensor.openweathermap_cloud_coverage
    domain: sensor
    above: 15
    below: 50
    for:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  condition:
  - condition: and
    conditions:
    - condition: sun
      before: sunset
      before_offset: -02:00:00
    - condition: time
      after: 09:00
  action:
  - service: light.turn_on
    target:
      entity_id: light.kitchen_main_lights
    data:
      brightness_pct: 25
  - service: light.turn_on
    target:
      entity_id: light.kitchen_under_cabinet
    data:
      brightness_pct: 60
  - service: switch.turn_off
    target:
      entity_id: switch.kitchen_sink_light

I’m not sure if this is proper to make the triggers work on the fly here. Additionally, I’m not sure about this -1 and 101 to capture 0 and 100 cloud coverage for triggers.

Any input is greatly appreciated.

Apparently I have an error in my YAML but I’m not finding it. I tried to add them in just to test and see if it would work, but it errs instead of reloading automations. Any thoughts out here for a newb?

I’m stuck at this error at the moment:

Invalid config for [automation]: value must be one of [‘apparent_power’, ‘battery_level’, ‘carbon_dioxide’, ‘carbon_monoxide’, ‘current’, ‘energy’, ‘frequency’, ‘gas’, ‘humidity’, ‘illuminance’, ‘nitrogen_dioxide’, ‘nitrogen_monoxide’, ‘nitrous_oxide’, ‘ozone’, ‘pm1’, ‘pm10’, ‘pm25’, ‘power’, ‘power_factor’, ‘pressure’, ‘reactive_power’, ‘signal_strength’, ‘sulphur_dioxide’, ‘temperature’, ‘value’, ‘volatile_organic_compounds’, ‘voltage’] for dictionary value @ data[‘type’]. Got None. (See /config/configuration.yaml, line 9).

Will test using “value” for the trigger as it seems generic enough.

When you created the automation’s Device Trigger, did you modify the value of its type option?

You have it set to cloudcover but the error message is telling you that it’s invalid and must but one of the listed values apparent_power, battery_level, carbon_dioxide, carbon_monoxide, etc.

Originally, I wrote this and posted without testing because I didn’t find guidance on what I was looking to do via my Google searches. This morning I went ahead and tried them out. I got the error posted. As noted, I redid it to use “value” as the trigger since it seems generic. But, I’m not seeing much in the way of guidance to know if value is the proper trigger to use.

FWIW, I’ve used cloud cover ranges for conditions and I’ve used temperatures for triggers. Temps have a range in the trigger so I was debating if “value” is improper and if I should use temperature. But, cloud cover is a percentage vs. a temperature being a real number so I decided to just stick with “value” for now.

Am I off base?

  trigger:
  - type: value
    platform: device
    device_id: 45a6ae64e81ca2ca86450430756e47f8
    entity_id: sensor.openweathermap_cloud_coverage
    domain: sensor
    above: -1
    below: 20
    for:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0

Use a Numeric State Trigger.

Okay so my revision of the trigger becomes:

  trigger:
  - type: value
    platform: numeric_state
    device_id: 45a6ae64e81ca2ca86450430756e47f8
    entity_id: sensor.openweathermap_cloud_coverage
    domain: sensor
    above: -1
    below: 20
    for:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0

Curiously, I have a few other triggers that use device using temperature ranges. Should I update these to numeric state as well?

Example:

  trigger:
  - type: temperature
    platform: device
    device_id: 52a7c56c24bf78a8eba58757bac2625e
    entity_id: sensor.temperature_14
    domain: sensor
    above: 10
    below: 79

Apologies I failed to reload the automation. Using the changes in the type: value and platform: numeric_state I end up with this error “Invalid config for [automation]: [type] is an invalid option for [automation]. Check: automation->type. (See /config/configuration.yaml, line 9).”

I suggested you use a Numeric State Trigger (and included a link to its documentation). You didn’t use a Numeric State Trigger but continued to use a Device Trigger (and simply altered the value of its platform option thereby creating a completely invalid trigger configuration).

Ah, yes stupid me. This has no errors returned when reloading automations:

  trigger:
   - platform: numeric_state
     entity_id: sensor.openweathermap_cloud_coverage
     above: 49
     below: 101
     for:
       hours: 0
       minutes: 1
       seconds: 0
       milliseconds: 0