Hey all,
I’ve got a working automation that forcibly discharges my home battery down to certain thresholds at various points in the day. Eg. at 20:30 it’ll discharge down to 50%, and at 21:30 it’ll discharge to 25% and so on. It look like this:
alias: "Libbi: Timed exports"
description: ""
trigger:
- platform: time
at: "20:30:00"
id: "2030"
- platform: time
at: "21:30:00"
id: "2130"
- platform: time
at: "22:30:00"
id: "2230"
- platform: time
at: "23:00:00"
id: "2300"
condition:
- condition: not
conditions:
- condition: state
entity_id: sensor.myenergi_zappi_22100218_status
state: Boosting
action:
- choose:
- conditions:
- condition: trigger
id:
- "2030"
- condition: numeric_state
entity_id: sensor.myenergi_libbi_24049368_soc
above: 50
sequence:
- service: notify.telegram_us
data:
data:
message_tag: libbi
message: >-
Libbi at {{ states('sensor.myenergi_libbi_24049368_soc') }}%
charge. Exporting to 25%
- if:
- condition: state
entity_id: sensor.myenergi_zappi_22100218_plug_status
state: EV Connected
then:
- device_id: 29e9524df6815f8f22c8b154295dcf8d
domain: select
entity_id: 201e81484bc3aa7f614de6916ddc9c80
type: select_option
option: Stopped
- device_id: 8c1f789db93bb94e82f47e9fda5ba4f1
domain: select
entity_id: efbdc28be6e6c52562e33d7d4492fa1f
type: select_option
option: Export
- wait_for_trigger:
- platform: state
entity_id:
- sensor.myenergi_libbi_24049368_soc
to: "25"
timeout:
hours: 0
minutes: 59
seconds: 30
milliseconds: 0
continue_on_timeout: false
- device_id: 8c1f789db93bb94e82f47e9fda5ba4f1
domain: select
entity_id: efbdc28be6e6c52562e33d7d4492fa1f
type: select_option
option: Normal
- service: notify.telegram_us
data:
data:
message_tag: libbi
message: Export stopped.
- if:
- condition: state
entity_id: select.myenergi_zappi_22100218_charge_mode
state: Stopped
then:
- device_id: 29e9524df6815f8f22c8b154295dcf8d
domain: select
entity_id: 201e81484bc3aa7f614de6916ddc9c80
type: select_option
option: Eco+
… And then there’s 3 more options that do the exact same sequence just with the different time and SoC conditions. It works but it’s obviously super clunky, so I’ve been trying to convert that sequence into a script in order to simplify it. So now, for the first block, I’m just doing this:
action:
- choose:
- conditions:
- condition: trigger
id:
- "2030"
- condition: numeric_state
entity_id: sensor.myenergi_libbi_24049368_soc
above: 50
sequence:
- service: script.libbi_export
data:
target: "50"
And then my script contains the main sequence:
alias: Libbi Export
sequence:
- service: notify.telegram_me
data:
data:
message_tag: libbi
message: >-
Libbi at {{ states('sensor.myenergi_libbi_24049368_soc') }}% charge.
Exporting to {{ target }}%
- if:
- condition: state
entity_id: sensor.myenergi_zappi_22100218_plug_status
state: EV Connected
then:
- device_id: 29e9524df6815f8f22c8b154295dcf8d
domain: select
entity_id: 201e81484bc3aa7f614de6916ddc9c80
type: select_option
option: Stopped
- device_id: 8c1f789db93bb94e82f47e9fda5ba4f1
domain: select
entity_id: efbdc28be6e6c52562e33d7d4492fa1f
type: select_option
option: Export
- wait_for_trigger:
- platform: state
entity_id:
- sensor.myenergi_libbi_24049368_soc
to: "{{ target }}"
timeout:
hours: 0
minutes: 59
seconds: 30
milliseconds: 0
continue_on_timeout: false
- device_id: 8c1f789db93bb94e82f47e9fda5ba4f1
domain: select
entity_id: efbdc28be6e6c52562e33d7d4492fa1f
type: select_option
option: Normal
- service: notify.telegram_me
data:
data:
message_tag: libbi
message: Export stopped.
- if:
- condition: state
entity_id: select.myenergi_zappi_22100218_charge_mode
state: Stopped
then:
- device_id: 29e9524df6815f8f22c8b154295dcf8d
domain: select
entity_id: 201e81484bc3aa7f614de6916ddc9c80
type: select_option
option: Eco+
mode: single
icon: mdi:battery-arrow-down
Where I’m coming unstuck is that the {{ target }}
variable works great inside the notification message, but I can’t make it work inside the wait_for_trigger
action.
After a lot of Googling I’ve also tried doing it as a wait_template
in various guises but none of these work either:
- wait_template: "{{ is_state('sensor.myenergi_libbi_24049368_soc','{{ target }}') }}"
timeout: "00:59:30"
continue_on_timeout: false
and (with and without single quotes around target
):
- wait_template: "{{ is_state('sensor.myenergi_libbi_24049368_soc',target) }}"
timeout: "00:59:30"
continue_on_timeout: false
Very much clutching at straws, but as this is reporting battery level, perhaps I need to include the % sign, but I can’t make that work either.
I feel like this must be possible but I’m pulling my hair out trying to get the syntax right! After what feels like a wasted afternoon I’m very much open to any suggestions here.
Thanks everyone.