Rain and illuminance sensor automation [RB-SRAIN01]

Hello!

A strange problem appeared last week; this sensor updates no longer trigger my automation in any way: numeric value or template.

I have an automation to track the MAX value of illuminance; this value corresponds to sunny weather, so my automation announces that today is a sunny day and saves this as a calendar event.

But from the last update, my automation is no longer triggered, no matter what.
I’ve created a separate sensor to be double-sure I covered everything from my side.

It will register changes as soon as I restart the Zb2MQTT addon or HA completely.

I’ve tested everything, and I can force this automation to work if I directly trigger it by the time of the day 18:00 to check if there WAS a peak in illuminance during the day.

Are there any changes to how it now triggers?
Why don’t any of the template checks won’t pass, even when template debug shows them all true?

Custom sensor:

Code
sensor:
  # Rain Sensor Illuminance (from raw value)
  - platform: statistics
    name: "Rain Sensor Illuminance Raw Max"
    entity_id: sensor.rain_illuminance_raw
    unique_id: rain_sensor_illuminance_raw_max
    state_characteristic: value_max
    sampling_size: 1000
    max_age:
      hours: 24

Statistics

And the graph is working as expected:

Code
type: custom:plotly-graph
title: Інтенсивність Світла
entities:
  - entity: sensor.rain_illuminance_raw
    name: Світло
    filters:
      - filter: i=1
      - resample: 1m
      - exponential_moving_average:
          alpha: 0.1
    show_value: true
    line:
      width: 1
      color: rgba (255, 200, 100, 100)
logarithmic_scale: true
hours_to_show: 240
refresh_interval: 15
grid_options:
  columns: 12
layout:
  dragmode: pan
  height: 450
  margin:
    b: 120
  legend:
    itemwidth: 80
  xaxis:
    rangeselector:
      "y": "-.3"
      buttons:
        - count: 3
          step: hour
        - count: 6
          step: hour
        - count: 12
          step: hour
        - count: 1
          step: day
        - count: 2
          step: day
        - count: 7
          step: day
        - count: 14
          step: day
        - count: 30
          step: day
config:
  scrollZoom: false
  doubleClickDelay: 600

Log

The activity is ok:

Last updated: recently and just fine.

Debug

Automation

And the automation:
Note: disabled parts are for debugging.

Code
alias: Sunny day calendar event
description: |-
  Register a sunny day in Sunny Day calendar.
  Check if event is already exists.
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.rain_sensor_illuminance_raw_max
    above: 6100
    id: sunny_day_max
  - trigger: numeric_state
    entity_id:
      - sensor.rain_illuminance_average_20min
    above: 6100
    id: sunny_day_max_2
  - trigger: numeric_state
    entity_id:
      - sensor.rain_illuminance_maximum_today
    above: 6100
    id: sunny_day
    enabled: true
  - trigger: template
    value_template: >-
      {% if states('sensor.rain_sensor_illuminance_raw_max')|float > 6100 %}{{
      True }}{% endif %}
    id: sunny_day_trigger
  - trigger: template
    value_template: "{{ states('sensor.rain_sensor_illuminance_raw_max')|float > 6100 }}"
    id: sunny_day_trigger_2
  - trigger: template
    value_template: "{{ states('sensor.rain_illuminance_raw')|float > 6100 }}"
    id: sunny_day_trigger_3
  - trigger: template
    value_template: "{{ states('sensor.rain_illuminance_average_20min')|float > 6100 }}"
    id: sunny_day_trigger_4
  - trigger: time
    at: "18:00:00"
    id: check_the_day
  - trigger: state
    entity_id:
      - input_boolean.test_input_boolean
    from: "off"
    to: "on"
    id: from_off_to_on
    enabled: false
conditions: []
actions:
  - variables:
      today_is_sunny_day: 0
  - if:
      - condition: and
        conditions:
          - condition: numeric_state
            entity_id: sensor.rain_illuminance_maximum_today
            above: 6100
          - condition: numeric_state
            entity_id: sensor.rain_sensor_illuminance_raw_max
            above: 6100
          - condition: template
            value_template: >-
              {{ states('sensor.rain_sensor_illuminance_raw_max')|float > 6100
              }}
          - condition: template
            value_template: "{{ states('sensor.rain_illuminance_average_20min')|float > 6100 }}"
          - condition: template
            value_template: "{{ states('sensor.rain_illuminance_raw')|float > 6100 }}"
    then: []
    enabled: false
  - choose:
      - conditions:
          - condition: trigger
            id:
              - sunny_day
              - from_off_to_on
              - sunny_day_max
              - sunny_day_max_2
              - sunny_day_trigger
              - sunny_day_trigger_2
              - sunny_day_trigger_3
              - sunny_day_trigger_4
        sequence:
          - action: calendar.get_events
            metadata: {}
            target:
              entity_id: calendar.sunny_day
            data:
              start_date_time: "{{ now().replace(hour=0, minute=0, second=0) }}"
              end_date_time: "{{ now().replace(hour=23, minute=59, second=59) }}"
            response_variable: today_is_sunny_day
          - if:
              - condition: template
                value_template: >-
                  {% for event in
                  today_is_sunny_day["calendar.sunny_day"]["events"] %}{{ true
                  }}{% endfor %}
            then:
              - action: persistent_notification.create
                metadata: {}
                data:
                  title: Sunny day
                  message: >-
                    Today was a sunny day!

                    Event created

                    {% for event in
                    today_is_sunny_day["calendar.sunny_day"]["events"] %}
                      {{ event.summary }} started: {{ event.start}}<br>
                    {% endfor %}
              - action: script.turn_on
                metadata: {}
                data:
                  variables:
                    media_id: >-
                      media-source://media_source/local/HA_Media/uplight-piano-short.mp3
                    content_type: audio/mpeg
                    message_to_announce: сьогодні був сонячний день!
                target:
                  entity_id: script.notification_and_tts
            else:
              - action: calendar.create_event
                metadata: {}
                target:
                  entity_id: calendar.sunny_day
                data:
                  summary: Sunny day
                  description: Sunny day
                  start_date_time: "{{ now() }}"
                  end_date_time: "{{ now() + timedelta(minutes=5)}}"
              - action: script.turn_on
                metadata: {}
                data:
                  variables:
                    media_id: >-
                      media-source://media_source/local/HA_Media/uplight-piano-short.mp3
                    content_type: audio/mpeg
                    message_to_announce: сьогодні сонячний день!
                target:
                  entity_id: script.notification_and_tts
      - conditions:
          - condition: trigger
            id:
              - check_the_day
        sequence:
          - if:
              - condition: numeric_state
                entity_id: sensor.rain_illuminance_maximum_today
                above: 6100
            then:
              - action: calendar.get_events
                metadata: {}
                target:
                  entity_id: calendar.sunny_day
                data:
                  start_date_time: "{{ now().replace(hour=0, minute=0, second=0) }}"
                  end_date_time: "{{ now().replace(hour=23, minute=59, second=59) }}"
                response_variable: today_is_sunny_day
              - if:
                  - condition: template
                    value_template: >-
                      {% for event in
                      today_is_sunny_day["calendar.sunny_day"]["events"] %}{{
                      true }}{% endfor %}
                then:
                  - action: persistent_notification.create
                    metadata: {}
                    data:
                      title: Sunny day
                      message: >-
                        Today was a sunny day!

                        Event created

                        {% for event in
                        today_is_sunny_day["calendar.sunny_day"]["events"] %}
                          {{ event.summary }} started: {{ event.start}}<br>
                        {% endfor %}
                  - action: script.turn_on
                    metadata: {}
                    data:
                      variables:
                        media_id: >-
                          media-source://media_source/local/HA_Media/uplight-piano-short.mp3
                        content_type: audio/mpeg
                        message_to_announce: сьогодні був сонячний день!
                    target:
                      entity_id: script.notification_and_tts
                else:
                  - action: calendar.create_event
                    metadata: {}
                    target:
                      entity_id: calendar.sunny_day
                    data:
                      summary: Sunny day
                      description: Sunny day
                      start_date_time: "{{ now() }}"
                      end_date_time: "{{ now() + timedelta(minutes=5)}}"
                  - action: script.turn_on
                    metadata: {}
                    data:
                      variables:
                        media_id: >-
                          media-source://media_source/local/HA_Media/uplight-piano-short.mp3
                        content_type: audio/mpeg
                        message_to_announce: сьогодні був сонячний день!
                    target:
                      entity_id: script.notification_and_tts
mode: single

The device:

Zigbee Model
TS0207
_TZ3210_tgvtvdoc (Solar rain sensor)

Model
RB-SRAIN01

Tuya

Related issues:

UPD: And as soon as I added one template sensor and reloaded configs, it triggered!

I added another template sensor just for testing:

template:
  - sensor:
      # Additional state class change
      - name: "Rain Sensor Illuminance Lx Fake"
        unique_id: rain_sensor_illuminance_fake
        state_class: measurement
        state: >
          {{ states('sensor.rain_illuminance_raw') | int }}

UPD 2: The fake Lx sensor fixed the issue; it now triggers as expected.

Hello Ole D,

It would help if you could to provide some code so we can see what you’ve done so far… We won’t be able to help if all we have is ‘I want to do this thing with this other thing’.

It makes it much easier for us to offer constructive answers if you follow Community Guidelines #9. 11, & 14 by supplying a properly formatted configuration for the automation that you have attempted.
Please share the YAML and any errors so we can see what you’ve done.

YAML is under the spoiler for every step: sensor, graph, automation.

However, the issue was fixed as soon as I added a “fake” sensor.
It started working as expected today, in the morning.
The code is also in the post.