I’m trying to set up an automation that can reset the power usage of my house at midnight.
My current automation is
- id: 'set_power_consumpton'
alias: 'set_power_consumpton'
initial_state: true
trigger:
platform: time
at: '00:00:00'
action:
- service: script.reset_consumption
data:
entity_id: sensor.power_consumption_normal
- service: script.reset_consumption
data:
entity_id: sensor.power_consumption_low
- service: script.reset_consumption
data:
entity_id: sensor.power_production_normal
- service: script.reset_consumption
data:
entity_id: sensor.power_production_low
- service: script.reset_consumption
data:
entity_id: sensor.gas_consumption
and script
reset_consumption:
sequence:
- service: input_number.set_value
data_template:
entity_id: >
{% set lst = entity_id.split('.') %}
input_number.midnight_{{ lst[1] }}
value: "{{ states(entity_id) }}"
However I can’t get it to work, home assistant reports.
Error while executing automation automation.set_power_consumpton. Invalid data for call_service at pos 1: Entity ID "input_number.midnight_power_consumption_normal" is an invalid entity id for dictionary value @ data['entity_id']
“input_number.midnight_power_consumption_normal” is in fact a valid entity and is visible in the UI.
I did have 5 automations before but all of it was code duplication which I don’t like. Using templates I feel it must be possible to do it with one script.
What am I missing here? I could also try yaml anchors but would rather using jinja.