Hi folks,
I’ve got a working template sensor (currently returning 96) but when I try to set another sensor to its value the automation says it’s not getting a float. Me confused!
Edited to remove screenshots and add code.
Automation:
alias: Set target SOC v03
description: ""
trigger: []
condition: []
action:
- service: number.set_value
data:
value: states('sensor.sol_calc_target_soc') | float
target:
entity_id: number.givtcp_sd2227g949_target_soc
mode: single
Template Sensor:
template:
- sensor:
- name: sys_sol_active_forecast
unit_of_measurement: "kWh"
state: >
{% if now().hour < 7 %} {{ states('sensor.energy_production_today') }}
{% else %} {{ states('sensor.energy_production_tomorrow') }}
{% endif %}
- name: "sol_calc_target_soc"
unit_of_measurement: "%"
state: >
{% set af = states('sensor.sys_sol_active_forecast') | float %}
{% set ls = states('input_number.sys_sol_low_solar') | float %}
{% set hs = states('input_number.sys_sol_high_solar') | float %}
{% set maxsoc = states('input_number.sys_sol_max_soc') | float %}
{% set minsoc = states('input_number.sys_sol_min_soc') | float %}
{% if af < ls %} {{ maxsoc }}
{% elif af > hs %} {{ minsoc }}
{% else %} {{ maxsoc - (af - ls) / (hs - ls) * (maxsoc - minsoc) }}
{% endif %}
The error is:
Stopped because an error was encountered at 29 January 2023 at 12:27:54 (runtime: 0.02 seconds)
expected float for dictionary value @ data[‘value’]
I’ve tried (because I’ve seen lots of examples with different formats):
{{ }} around it all.
“{{ }}” around it all.
With and without state()
With and without single quotes around the sensor name.
With and without sensor.
Maybe I’m missing a combination of the above?