Simple automation based on the current weather

That was just a spitball, @123’s solution is what you want so you don’t have that problem. If I had thought my solution fully through I would have realized it would cause the very problem you are having.

Yes, actually it was as I had written it at the beginning. The problem is that if the weather change from “rainy” to “lightning” it makes no sense to send the input to close the shutters if they are already closed by the previous step (“sunny” to “rainy”).

The purpose was to send the input only when the state changed from a good weather state to a bad weather state.

@123’s solution will also send you a notification if the weather changes from one bad condition to another. Without both the to and from, you don’t know if you need a notification sent as you don’t have the good / bad state stored anywhere else.

I’d suggest creating a binary_sensor for bad weather, and set the notification from that. With the new template format:

template: 
  - binary_sensor:
      - name: bad_weather
        state: >-
          {{ states('weather.casa') in ['hail',
                                        'lightning',
                                        'lightning-rainy',
                                        'pouring',
                                        'rainy',
                                        'snowy',
                                        'snowy-rainy'] }}

and then:

- id: '1620898331665'
  alias: Tapparelle Abbassa per meteo
  trigger:
  - platform: state
    entity_id: binary_sensor.bad_weather
    to: 'on'
  action:
  - service: notify.mobile_app_xxx
    data:
      title: Abbassa tapparelle
  mode: single
1 Like

This rejects a change from one foul-weather state to another.

- id: '1620898331665'
  alias: Tapparelle Abbassa per meteo
  description: ''
  trigger:
  - platform: state
    entity_id: weather.home
    to:
      - "hail"
      - "lightning"
      - "lightning-rainy"
      - "pouring"
      - "rainy"
      - "snowy"
      - "snowy-rainy"
  condition: '{{ trigger.from_state.state not in ["hail", "lightning", "lightning-rainy", "pouring", "rainy", "snowy", "snowy-rainy"] }}'
  action:
  - service: notify.mobile_app_xxx
    data:
      title: Abbassa tapparelle
  mode: single

EDIT

Correction. Fixed trigger.from_state.state (as noted by Troon in post below).

1 Like

True, but it does no harm either as HA will know it’s already closed and not send a command to close it again (depending on how your device is configured). If you tell it to close again and it’s closed, no big deal, it’s actually a safety net in case for some reason it didn’t close before ;).

1 Like

I’m receiving "Message malformed: extra keys not allowed @ data[‘0’] " when iI try this code. Anyone know what might be the problem is?

Where did you copy-paste it?

  1. automations.yaml
  2. configuration.yaml
  3. YAML mode of the Automation Editor.

If you copy-pasted it into #3 then replace the leading hypen on the first line with a space.

There’s a typo in the condition (although that’s not the cause of the error) — should be trigger.from_state not trigger.from.state.

1 Like

Thank you! Fixed.

FWIW, Eliozhang310 had replied to one of my previous posts (the earlier version of the example without the reference to the trigger object). Nevertheless, you’re right about the typo in the next example and I have corrected it.

1 Like