Anyone know why the scope of the response variable doesn't extend to the sensors?

Hi,

I’m trying to get weatherman data tag working - it’s a weather app for openepaper.

https://github.com/chunkysteveo/OpenEPaperLink-HA-Weatherman
The structure is such that I’ve put the code that is meant to go into the configuration.yaml file into templates.yaml and re-directed to that.

Within the templates.yaml, I have the following code:

- trigger:
    platform: time_pattern
    minutes: "/15"
    variables:
      forecast_entity: 'weather.home'
  action:
    - service: weather.get_forecasts
      target:
          entity_id: "{{forecast_entity}}"
      data:
          type: hourly
      response_variable: weather_home_hourly
    - service: weather.get_forecasts
      target:
          entity_id: "{{forecast_entity}}"
      data:
          type: daily
      response_variable: weather_home_daily  

- sensor:
    - name: Weatherman Data Tag
      state: "{{ now().isoformat() }}"
      attributes:
          moon_phase: >
            {% set cond_moon = states('sensor.moon_phase') %}
            {% if cond_moon == 'new_moon' %}
...

          wm_cond_0: >
            {% set cond0 = weather_home_hourly['weather.home']['forecast'][0].condition %}
            {% if cond0 == 'partlycloudy' %}{% set cond0 = 'partly-cloudy' %}{% endif %}
            {% if cond0 == 'clear-night' %}{% set cond0 = 'night' %}{% endif %}
            {% set next_setting = as_timestamp(state_attr('sun.sun', 'next_setting')) %}
            {% set next_rising = as_timestamp(state_attr('sun.sun', 'next_rising')) %}
            {% set cond0_time = as_timestamp(weather_home_hourly['weather.home']['forecast'][0].datetime) %}
            {% if states('sun.sun') == 'above_horizon' and cond0_time > next_setting %}
                {% if cond0 == 'sunny' %} night {% elif cond0 == 'partly-cloudy' %} night-partly-cloudy {% else %} {{ cond0 }} {% endif %}
            {% elif states('sun.sun') == 'below_horizon' and cond0_time < next_rising %}
                {% if cond0 == 'sunny' %} night {% elif cond0 == 'partly-cloudy' %} night-partly-cloudy {% else %} {{ cond0 }} {% endif %}    
            {% else %}
                {{ cond0 }}
            {% endif %}

The issue is that the response variables are null when they hit the sensor: fields

I suspect it is some formatting issue - within configuration.yaml, I have the following

template: !include templates.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml
shell_command: !include shell.yaml
rest_command: !include rest.yaml
emulated_hue: !include emulated_hue.yaml
recorder: !include recorder.yaml

is there some way I can fix this?

Remove the hyphen in front of sensor. By including it you have defined a new state-based template sensor with no relation to the previously defined trigger and action.

1 Like

Unfortunately that didn’t do anything. I’m still getting null values.

Have you reloaded? That extra hyphen is the problem. Please re-post the corrected config if you still think it’s not working. Note that the sensor will only update every 15 minutes so you may need to wait for the first update.

Put a test attribute in:

      attributes:
          forecast: "{{ weather_home_hourly['weather.home']['forecast'] }}"
          moon_phase: >
             [etc]

OOps - my mistake - yes, working now Thanks

1 Like