#Trigger for rain automation

1 messages · Page 1 of 1 (latest)

fringe tendon
#

I can get an hourly forcast that looks like this from a service

service: weather.get_forecasts
target:
  entity_id: weather.city_forecast
data:
  type: hourly
response_variable: hourly

Response
weather.london_forecast:
  forecast:
    - datetime: "2024-06-05T05:00:00+00:00"
      condition: partlycloudy
      precipitation_probability: 20
      temperature: 20
    - datetime: "2024-06-05T06:00:00+00:00"
      condition: clear-night
      precipitation_probability: 20
      temperature: 19
    - datetime: "2024-06-05T07:00:00+00:00"
      condition: clear-night
      precipitation_probability: 20
      temperature: 19
    - datetime: "2024-06-05T08:00:00+00:00"
      condition: clear-night
      precipitation_probability: 20
      temperature: 19
    - datetime: "2024-06-05T09:00:00+00:00"
      condition: partlycloudy
      precipitation_probability: 20
      temperature: 19
    - datetime: "2024-06-05T10:00:00+00:00"
      condition: partlycloudy
      precipitation_probability: 20
      temperature: 20
    - datetime: "2024-06-05T11:00:00+00:00"
      condition: partlycloudy
      precipitation_probability: 20
      temperature: 20
    - datetime: "2024-06-05T12:00:00+00:00"
      condition: partlycloudy
      precipitation_probability: 20
      temperature: 21
    - datetime: "2024-06-05T13:00:00+00:00"
      condition: rainy
      precipitation_probability: 80
      temperature: 21
    - datetime: "2024-06-05T14:00:00+00:00"
      condition: rainy
      precipitation_probability: 80
      temperature: 20

How can I basically say if it sees rain coming in an hour or so to check door/window contacts send message to close...
The end part is basically done from the prior hvac testing code just not sure how to trigger the timed rain trigger for it?

#
alias: "Rain Warning"
description: ""

trigger: ??

condition:
  - condition: template
    value_template: "{{ open | count > 0 }}"
action:
  - service: notify.all_devices
    data:
      message: "Following are open with rain on the way: {{ open | join(', ') }}"
variables:
  entities: >
    [{% for i in [1,2,3,4,6,7] %}"binary_sensor.ttgo_poe_001_zone_{{ '%02i'%i
    }}",{% endfor %}]
  open: >
    {{ entities | select('is_state', 'on') | map('state_attr', 'friendly_name')
    | sort }}
mode: single
urban zealot
#

Have you tested that action sequence? I don't think your variables will work. The variable open expects a list, entities is not a list. At best, it's a list-shaped string.

Regarding the trigger. A place to start would be a time pattern trigger set for whatever interval you want the forecast to be checked.

fringe tendon
#

Yes the action sequence works for my heating / cooling hvac is on then warn the windows are open currently

fringe tendon
#
alias: Rain Warning Close All Windows and Doors
description: "If the weather report shows rain, check if windows/doors are open, send message to all devices."
trigger:
  - platform: time_pattern
    hours: /1
condition:
  - condition: template
    value_template: "{{ open | count > 0 }}"
action:
  - service: weather.get_forecasts
    target:
      entity_id: weather.city_forecast
    data:
      type: hourly
    response_variable: hourly
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ 'rain' in hourly['weather.city_forecast'].forecast[0].condition
              }}
        sequence:
          - service: notify.all_devices
            data:
              message: >-
                Following are open with rainy weather on the way: {{ open |
                join(', ') }}
variables:
  entities: >
    [{% for i in [1,2,3,4,6,7] %}"binary_sensor.ttgo_poe_001_zone_{{ '%02i'%i
    }}",{% endfor %}]
  open: >
    {{ entities | select('is_state', 'on') | map('state_attr', 'friendly_name')
    | sort }}
mode: single
#

Executed: June 5, 2024 at 1:51:51 AM
Result:
result: null
conditions/0
Executed: June 5, 2024 at 1:51:51 AM
Error: In 'template' condition: UndefinedError: 'dict object' has no attribute 'weather'

#
conditions:
  - condition: template
    value_template: '{{ ''clear'' in hourly.weather.city_forecast.forecast[0].condition }}'
sequence:
  - service: notify.all_devices
    data:
      message: >-
        Following are open with clear weather on the way: {{ open | join(', ')
        }}
pure finch
#

You need to use hourly['weather.city_forecast'].forecast[0]

fringe tendon
#

Thank you that worked

whole cave
#

@fringe tendon any chance you can put the full automation please 🙂

whole cave
#

also how are you preventing the notification from coming up every minute?