Your trigger-based forecast query has no sensor key… which is Required. The best thing to do would be to set up a sensor for each of the values you need from the forecast, then retrieve those states in your Weatherman Data Tag sensor where needed.
Im not sure I understand - shouldn’t the response variable contain the values that the weatherman sensor extracts as in the code above. My problem is the response variables aren’t accessible in the sensor block.
Thanks, Yes - did that and it worked! - yes, I’ll change the frequency - I moved it to a minute for a test.
So other sensors in the templates.yaml file should initially start with:
…
- name: APF Grid Entity
device_class: power
state_class: measurement
unit_of_measurement: W
state: "{{ (0 - states('sensor.powerwall_site_now')|float(0)*1000)|int(0) }}"
# sensor must always be 0 or positive (i think they always are)
- name: APF House Entity
device_class: power
state_class: measurement
unit_of_measurement: W
state: "{{ (states('sensor.powerwall_load_now')|float(0)*1000)|int(0) }}"
# sensor must always be 0 or positive (i think they always are)
- name: APF Generation Entity
device_class: power
state_class: measurement
unit_of_measurement: W
state: "{{ (states('sensor.powerwall_solar_now')|float(0)*1000)|int(0) }}"
# battery sensor must be positive when charging and negative when discharging
- name: APF Battery Entity
device_class: power
state_class: measurement
unit_of_measurement: W
state: "{{ (0 - states('sensor.powerwall_battery_now')|float(0)*1000)|int(0) }}"
# Required to reduce code later on
- name: APF Grid Import
device_class: power
state_class: measurement
unit_of_measurement: W
state: >
{% if states('sensor.apf_grid_entity')|int(default=0) < 0 %}
{{ states('sensor.apf_grid_entity')|int(default=0)|abs }}
{% else %}
0
{% endif %}
# Inverter consumption and power losses due to Inverter transfers and power conversions (AC/DC)
# excludes rounding errors made worst by the fact that some inverters round all sensors readings to INT
# Occasionally this might be negative probably due to cumulative errors in not so accurate power readings.
- name: APF Inverter Power Consumption
device_class: power
state_class: measurement
unit_of_measurement: W
state: "{{ states('sensor.apf_generation_entity')|int(default=0) - states('sensor.apf_battery_entity')|int(default=0) - states('sensor.apf_house_entity')|int(default=0) - states('sensor.apf_grid_entity')|int(default=0) }}"
# Real House Load Includes Inverter consumption and transfer conversions and losses and rounding errors.
# It never made sense that inbound power sometimes does not equal outbound power. This fixes it!
- name: APF Real House Load
device_class: power
state_class: measurement
unit_of_measurement: W
state: "{{ states('sensor.apf_house_entity')|int(default=0) + states('sensor.apf_inverter_power_consumption')|int(default=0) }}"
icon: mdi:home-lightning-bolt
- name: APF Grid2House
device_class: power
state_class: measurement
unit_of_measurement: W
state: >
{% if states('sensor.apf_grid_import')|int(default=0) > states('sensor.apf_real_house_load')|int(default=0) %}
{{ states('sensor.apf_real_house_load')|int(default=0) }}
{% else %}
{{ states('sensor.apf_grid_import')|int(default=0) }}
{% endif %}
- name: APF Grid2Batt
device_class: power
state_class: measurement
unit_of_measurement: W
state: >
{% if states('sensor.apf_grid_import')|int(default=0) > states('sensor.apf_real_house_load')|int(default=0) %}
{{ states('sensor.apf_grid_import')|int(default=0) - states('sensor.apf_real_house_load')|int(default=0) }}
{% else %}
0
{% endif %}
- name: APF Batt2House
device_class: power
state_class: measurement
unit_of_measurement: W
state: >
{% if states('sensor.apf_battery_entity')|int(default=0) < 0 %}
{% if states('sensor.apf_battery_entity')|int(default=0)|abs > states('sensor.apf_real_house_load')|int(default=0) %}
{{ states('sensor.apf_real_house_load')|int(default=0) }}
{% else %}
{{ states('sensor.apf_battery_entity')|int(default=0)|abs }}
{% endif %}
{% else %}
0
{% endif %}
# This might be called house to grid, and can happen in rare circumstances,
# like when the inverter is not able to do a precise adjustment of power fast enough
# or when you want to force a discharge of the battery or something...
# But it only happens with battery or other power generator users.
- name: APF Batt2Grid
device_class: power
state_class: measurement
unit_of_measurement: W
state: >
{% if states('sensor.apf_battery_entity')|int(default=0) < 0 %}
{% if states('sensor.apf_battery_entity')|int(default=0)|abs > states('sensor.apf_real_house_load')|int(default=0) %}
{{ states('sensor.apf_battery_entity')|int(default=0)|abs - states('sensor.apf_real_house_load')|int(default=0) }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
- name: APF Solar2Grid
device_class: power
state_class: measurement
unit_of_measurement: W
state: >
{% if states('sensor.apf_grid_entity')|int(default=0) > states('sensor.apf_batt2grid')|int(default=0) %}
{{ states('sensor.apf_grid_entity')|int(default=0) - states('sensor.apf_batt2grid')|int(default=0) }}
{% else %}
0
{% endif %}
- name: APF Solar2House
device_class: power
state_class: measurement
unit_of_measurement: W
state: >
{% if states('sensor.apf_generation_entity')|int(default=0) > 0 and states('sensor.apf_real_house_load')|int(default=0) > states('sensor.apf_batt2house')|int(default=0) + states('sensor.apf_grid_import')|int(default=0) %}
{% if states('sensor.apf_generation_entity')|int(default=0) > states('sensor.apf_real_house_load')|int(default=0) - states('sensor.apf_batt2house')|int(default=0) - states('sensor.apf_grid2house')|int(default=0) %}
{{ states('sensor.apf_real_house_load')|int(default=0) - states('sensor.apf_batt2house')|int(default=0) - states('sensor.apf_grid2house')|int(default=0) }}
{% else %}
{{ states('sensor.apf_generation_entity')|int(default=0) }}
{% endif %}
{% else %}
0
{% endif %}
- name: APF Solar2Batt
device_class: power
state_class: measurement
unit_of_measurement: W
state: >
{% if states('sensor.apf_generation_entity')|int(default=0) > 0 and states('sensor.apf_battery_entity')|int(default=0) > 0 %}
{% if states('sensor.apf_battery_entity')|int(default=0) > states('sensor.apf_grid2batt')|int(default=0) %}
{% if states('sensor.apf_generation_entity')|int(default=0) - states('sensor.apf_solar2house')|int(default=0) > states('sensor.apf_battery_entity')|int(default=0) - states('sensor.apf_grid2batt')|int(default=0) %}
{{ states('sensor.apf_battery_entity')|int(default=0) - states('sensor.apf_grid2batt')|int(default=0) }}
{% else %}
{{ states('sensor.apf_generation_entity')|int(default=0) - states('sensor.apf_solar2house')|int(default=0) - states('sensor.apf_solar2grid')|int(default=0) }}
{% endif %}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
- name: Last Alexa
state: |-
{{ expand(integration_entities('alexa_media') | select('search', 'media_player'))
| selectattr('attributes.last_called', 'eq', True) | map(attribute='entity_id') | first }}
availability: |-
{{ expand(integration_entities('alexa_media') | select('search', 'media_player'))
| selectattr('attributes.last_called','eq',True) | first is defined }}