Irrigation Automation help

Hello,

I have the Smart Irrigation integration from HACS and I’m trying to stop the irrigation if more than 5mm of rain is expected in the next 24 hours. My problem is that the automation skips the “choose” option. Here is my code:

alias: Gartenbewässerung und Sensor-Reset steuern Hinten
trigger:
  - platform: sun
    event: sunrise
    offset: "-01:00:00"
    enabled: true
condition:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ state_attr('weather.home', 'forecast')[0].precipitation <= 5 }}"
          - condition: numeric_state
            entity_id: sensor.smart_irrigation_garten_hinten
            above: 0
        sequence:
          - service: switch.turn_on
            entity_id: switch.garten_pumpe
          - delay:
              seconds: 10
          - service: switch.turn_on
            entity_id: switch.garten_bewesserung_hinten
          - delay:
              seconds: "{{ states('sensor.smart_irrigation_garten_hinten') | int }}"
          - service: switch.turn_off
            entity_id: switch.garten_pumpe
          - service: switch.turn_off
            entity_id: switch.garten_bewesserung_hinten
          - service: smart_irrigation.reset_bucket
            target:
              entity_id: sensor.smart_irrigation_garten_hinten
            data: {}
      - conditions:
          - condition: template
            value_template: "{{ state_attr('weather.home', 'forecast')[0].precipitation > 5 }}"
        sequence:
          - service: smart_irrigation.reset_bucket
            target:
              entity_id: sensor.smart_irrigation_garten_hinten
            data: {}

And sorry, I’m new to Home Assistant.

Read up on the change to the weather entities. The forecast is no longer available as an attribute. I assume this code is copied from somewhere?

Kind of Chat GTP 4

Don’t use ChatGPT for HA. It’s terrible at it because it’s trained on old data including forum posts with non-working code.

Okay, I will avoid it then. However, I’m not good with code and only understand some parts. Is there a way you could help me with this configuration?

Yes. We’re going to have to get quite advanced here: due to a recent change, there are some steps to take to be able to access weather forecasts like you need to.

First of all, do you actually have a weather.home entity set up, or is that something that ChatGPT hallucinated?

If you do not, you’ll have to find and install a suitable weather integration for your location. Once you’ve done that, and assuming you’ve called it weather.home

You’ll need to add this code to your configuration:

template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.home
        response_variable: hourly
    sensor:
      - name: Weather forecast
        state: "{{ now() }}"
        attributes:
         - forecast: "{{ hourly['weather.home'].forecast }}"

Have a look in your configuration.yaml file (help). Do you already have a line like this or similar?

template: !include templates.yaml

If you do, then the code above goes into the referenced file (templates.yaml in my example here) without the first template: line.

If you do not, you can put the code straight into configuration.yaml, but make sure there’s only one template: line in the file.

Restart HA, and see if you have a sensor called sensor.weather_forecast. If you do, paste this into Developer Tools / Template and paste the first few lines of the result here formatted like your original automation code:

{{ states['sensor.weather_forecast'] }}

The result should look something like this:

<template TemplateState(<state sensor.weather_forecast'=2024-05-15T04:00Z; timeSeries=[{'time': '2024-05-13T00:00Z', 'midnight10MWindSpeed': 4.12, 'midnight10MWindDirection': 126, 'midnight10MWindGust': 9.26, 'midnightVisibility': 4698, 'midnightRelativeHumidity': 93.86, 'midnightMslp': 100100, 'nightMinScreenTemperature': 13.41, 'nightUpperBoundMinTemp': 14.23, 'nightLowerBoundMinTemp': 12.15, 'nightUpperBoundMinFeelsLikeTemp': 12.76, 'nightLowerBoundMinFeelsLikeTemp': 11.36}, {'time': '2024-05-14T00:00Z', 'midday10MWindSpeed': 5.35, 'midnight10MWindSpeed': 3.6, 'midday10MWindDirection': 138, 'midnight10MWindDirection': 104, 'midday10MWindGust': 7.2, 'midnight10MWindGust': 8.23, 'middayVisibility': 14182, 'midnightVisibility': 11172, 'middayRelativeHumidity': 81.02, 'midnightRelativeHumidity': 91.4, 'middayMslp': 99950, 'midnightMslp': 100250, 'maxUvIndex': 3, 'daySignificantWeatherCode': 7, 'nightSignificantWeatherCode': 12, 'dayMaxScreenTemperature': 17.22, 'nightMinScreenTemperature': 12.59, 'dayUpperBoundMaxTemp': 18.33, 'nightUpperBoundMinTemp': 13.64, 

Once we have that working, we can move onto the automation.

Okay, I’m already stuck here is my Configuration.yaml, I don’t have the sensor.


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
lovelace:
  mode: storage

#NOTIFICATION GROUP:
notify:
  - platform: group
    name: Family
    services:
      - service: mobile_app_novos_handy
#      - service: mobile_app_julia_handy
#     - service: mobile_app_nani_handy

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - IP ###(Nginx Proxy Manager LXC IP)###
# WOL
wake_on_lan:
switch:
  - platform: wake_on_lan
    mac: "MAC"
    name: NoVoS-WOL

# Garage
cover:
  - platform: template
    covers:
      garage_door1:
        friendly_name: "Garage Door 1"
        value_template: "{{ is_state('binary_sensor.garage_garage_door_contact', 'on') }}"
        open_cover:
          service: switch.turn_on
          entity_id: switch.garage_trigger
        close_cover:
          service: switch.turn_off
          entity_id: switch.garage_trigger
        icon_template: >-
          {% if is_state('cover.garage_door1', 'open') %}
            mdi:garage-open
          {% else %}
            mdi:garage
          {% endif %}

# Weather
template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.home
        response_variable: hourly
    sensor:
      - name: Weather forecast
        state: "{{ now() }}"
        attributes:
          - forecast: "{{ hourly['weather.home'].forecast }}"

Do you have a working weather integration set up? You must get that set up first, as per my previous post.

I’m using OpenWeatherMap

So no weather.home then, that was a GPT blind alley.

Looks like you do have some useful sensors there — have a look through what you have and see if any of those could be used in your automation.