I’m trying to simply set a value on a device I have an integration to, a numeric value to be set the value of a sensor from my config. I think this is one of the simpler things to do, but I must be going about it wrong. I have the device integration working fine and can set the value I need to a constant number without any problems. Now I try to move the target value to the value of the sensor above and I can’t get past errors about wanting a float type, even though I’m converting the sensor value to a float.
Here is the sensor, which does work fine and can be checked and displayed OK:
battery_set_charge_level:
friendly_name: "Battery Set Charge Level"
unique_id: battery_set_charge_level
value_template: >-
{% set f_avg = states('sensor.solarforecast')|float %}
{% set b_cap = states('input_number.full_battery_capacity')|float %}
{% set eff = states('input_number.inverter_efficiency')|float %}
{% set h_use = states('input_number.home_usage')|float %}
{% set min_charge_level = states('input_number.min_charge_level')|float %}
{% set charge_level = 100 * (1 - ((f_avg - h_use) / b_cap * eff/100)) %}
{% set charge_level = max(charge_level, min_charge_level) %}
{% if h_use > f_avg %}
{% set charge_level = 100 %}
{% endif %}
{{ charge_level }}
Here is my automation YAML code to try and set my device value from the above sensor:
alias: OctCozyStartOne
description: Octopus Cozy period 1 charge battery to max on very low expected solar yield
trigger:
- platform: time
at: input_datetime.octcozystart1
condition:
- condition: numeric_state
entity_id: sensor.lux_battery
below: 95
above: 0
action:
- device_id: e7f665cf7d024dd67f0553968fa6dbc5
domain: number
entity_id: number.lux_ac_battery_charge_level
type: set_value
value: {{ (states('sensor.battery_set_charge_level')|float) }}
mode: single
Now the errors I get when using the YAML format automation editing and save:
Message malformed: expected float for dictionary value @ data[‘value’]
Any thoughts?
And apologies in advance if I’ve posted this in the wrong place or with the wrong formatting. I did try but I don’t post often enough to remember the best ways.