Get value of variable for message

Hi,
I’ve a automation to turn off my water heating if the forecast cloud coverage is below a defined amount. (The necessary value I’m testing)
It seems to run properly but I get no value of the n_cloud_coverage in the message. So I’m also unsure, if the condition triggers in the way I want:

alias: 09:56 Brenner OFF
description: Brenner OFF wenn Aussentemp > 8°C und Vorhersage Bewölkung < 90%
triggers:
  - at: "09:56:00"
    trigger: time
conditions:
  - condition: numeric_state
    entity_id: sensor.temp_keller_aussen_temperature
    above: 8
actions:
  - target:
      entity_id: weather.forecast_home
    data:
      type: hourly
    response_variable: forecast_data
    action: weather.get_forecasts
  - if:
      - condition: template
        value_template: >
          {% set n_cloud_coverage =
          forecast_data['weather.forecast_home'].forecast[6].cloud_coverage %}
          {{ n_cloud_coverage < 95 }}
    then:
      - target:
          entity_id: 9d4d20356e7b640809d4a0f09c63e54f
        data: {}
        action: switch.turn_off
      - metadata: {}
        data:
          message: Brenner AUS (Vorhersage Bewölkung 14 Uhr {{ n_cloud_coverage }})
        action: notify.matrix_notify
mode: single

Can somebody give me a hint or see a misstake?

hi!

  1. before you starts to develop automation, always play with services what you plan to use in http://homeassistant.local:8123/developer-tools/action
  2. also i can recommend you use http://homeassistant.local:8123/developer-tools/template
  3. and final sandbox after you starts to develop automation

so, as you can see, not issues with n_cloud_coverage

  1. be sure what at 09:56:00 items number 6 is present in weather response

  2. be sure what your weather provider support cloud_coverage

That variable does not have a value in the notification action because it is outside its scope. There are a couple ways to solve this… I would define the variable more globally by using a Script variable:

alias: 09:56 Brenner OFF
description: Brenner OFF wenn Aussentemp > 8°C und Vorhersage Bewölkung < 90%
triggers:
  - at: "09:56:00"
    trigger: time
conditions:
  - condition: numeric_state
    entity_id: sensor.temp_keller_aussen_temperature
    above: 8
actions:
  - target:
      entity_id: weather.forecast_home
    data:
      type: hourly
    response_variable: forecast_data
    action: weather.get_forecasts
  - variables:
      n_cloud_coverage: "{{ forecast_data['weather.forecast_home'].forecast[6].cloud_coverage }}"
  - if:
      - condition: template
        value_template: "{{ n_cloud_coverage < 95 }}"
    then:
      - action: switch.turn_off
        target:
          entity_id: 9d4d20356e7b640809d4a0f09c63e54f
        data: {}
      - action: notify.matrix_notify
        metadata: {}
        data:
          message: Brenner AUS (Vorhersage Bewölkung 14 Uhr {{ n_cloud_coverage }})
mode: single

Thank you, that’s it!
I had suspected something like this, but didn’t know how to solve it.