template:
- trigger:
- platform: time_pattern
minutes: "/1"
- platform: state
entity_id: sensor.solcast_pv_forecast_prognose_heute
not_from:
- "unknown"
- "unavailable"
- "none"
not_to:
- "unknown"
- "unavailable"
- "none"
action:
- variables:
var: >-
{% from '032-emhass.jinja' import globalVariables %}
{{ globalVariables()|from_json }}
node: "{{ state_attr('sensor.solcast_pv_forecast_prognose_heute', 'detailedForecast') }}"
sensor:
- name: solcast_forecast_remaining_today_every_minute
unique_id: solcast_forecast_remaining_today_every_minute
#friendly_name: "Solcast Forecast Remaining Today (Every Minute)"
state_class: "total"
device_class: energy
unit_of_measurement: "kWh"
icon: mdi:solar-power
state: >-
{%- set node = state_attr('sensor.solcast_pv_forecast_prognose_heute', 'detailedForecast') %}
{%- set ts_end_time = ((as_timestamp(now().replace(day=now().day+1).replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0))/1800)|round(0,'floor')|int * 1800) %}
{% from '032-emhass.jinja' import forecastPeriod %}
{{ forecastPeriod(node, 'period_start', 'pv_estimate', 1, ts_end_time)|float(0) }}
attributes:
solar_noon_energy: >-
{%- set node = state_attr('sensor.solcast_pv_forecast_prognose_heute', 'detailedForecast') %}
{%- set ts_end_time = today_at(var.batteries_charge_end_time_expected).timestamp() %}
{% from '032-emhass.jinja' import forecastPeriod %}
{{ forecastPeriod(node, 'period_start', 'pv_estimate', 1, ts_end_time)|float(0) }}
solar_noon_time: "{{ var.batteries_charge_end_time_expected }}"
last_updated: "{{ now() }}"
The data I want to pass (variable node) :
If I pass the node data directly in the sensor state and in the attributes everything works fine.
Passing the node data via action variables results in sensor state unavailable …
The array passed via variable var is working fine:
{%- macro globalVariables() %}
{{- {
'inverter_rated_power': 6000,
'inverter_maximum_active_power': 6600,
'batteries_rated_capacity': 15,
'batteries_rated_charge_energy': 17.250,
'batteries_rated_discharge_power': 6600,
'batteries_rated_charge_power': 7500,
'batteries_charge_end_time_expected': '14:00',
'batteries_soc_setpoint_low': 15,
'epexspot_quantile_setpoint_low': 0.15,
'epexspot_quantile_setpoint_neutral': 0.33,
'epexspot_quantile_setpoint_high': 0.8
}|to_json -}}
{%- endmacro %}
I really needs to avoid redundant sensor calls because I want’s to setup an Energy Monitoring System with nearly real time monitoring.
1 post - 1 participant