I’m doing something wrong around line 35 with calling another state but don’t know what, please help
alias: BMW lader
description: ""
trigger:
- platform: state
entity_id:
- sensor.330e_xdrive_remaining_battery_percent
- platform: state
entity_id:
- binary_sensor.330e_xdrive_connection_status
condition: []
action:
- if:
- condition: and
conditions:
- condition: state
entity_id: device_tracker.330e_xdrive
state: home
- condition: state
entity_id: binary_sensor.330e_xdrive_connection_status
state: "on"
- condition: or
conditions:
- type: is_battery_level
condition: device
device_id: 0c62c1711be1cb1cde5e35ed103c3b8c
entity_id: 8bc9a09c65833cfe9c2da9d68b50434c
domain: sensor
below: 50
- type: is_value
condition: device
device_id: 9e9bfc80d501345762801a9ddd9c2cbd
entity_id: ea1ac9d9d2c04a2939ddefcd77277f05
domain: sensor
below: '{{ states(''sensor.energyzero_today_energy_average_price'') | float }}'
then:
- type: turn_on
device_id: 548737ce439d1589ae09c0ad25e40734
entity_id: 99b363003aa0ee3beff5b04e88f9350e
domain: switch
else:
- type: turn_off
device_id: 548737ce439d1589ae09c0ad25e40734
entity_id: 99b363003aa0ee3beff5b04e88f9350e
domain: switch
mode: single
in short: if my car is home and connected + if the energy price is below the daily avarage I want my car being charged. but if my car is below 50% I want it to charge to that miminum regardless of the price.
Device conditions (as well as triggers and actions) don’t accept templates. AFAIK, all the variations that check numerical values only allow numerical values in the above/below field, they do not allow comparison to the value of another entity like Numeric state conditions allow. If you want more dynamic automations you should stop using Device conditions.
alias: BMW lader
description: ""
trigger:
- platform: state
entity_id:
- sensor.330e_xdrive_remaining_battery_percent
- platform: state
entity_id:
- binary_sensor.330e_xdrive_connection_status
condition: []
action:
- if:
- condition: state
entity_id: device_tracker.330e_xdrive
state: home
- condition: state
entity_id: binary_sensor.330e_xdrive_connection_status
state: "on"
- condition: or
conditions:
- condition: numeric_state
entity_id: 8bc9a09c65833cfe9c2da9d68b50434c
below: 50
- condition: numeric_state
entity_id: ea1ac9d9d2c04a2939ddefcd77277f05
below: sensor.energyzero_today_energy_average_price
then:
- service: switch.turn_on
entity_id: 99b363003aa0ee3beff5b04e88f9350e
else:
- service: switch.turn_off
entity_id: 99b363003aa0ee3beff5b04e88f9350e
mode: single
1 Like
thanks, I manged to get it working. you are correct that the device_id & entity_id are annoying and with a bit of tinkering I resulted to below (for future reference or people like myself looking for a similar issue/solution)
alias: BMW lader
description: ""
trigger:
- platform: state
entity_id:
- sensor.330e_xdrive_remaining_battery_percent
- platform: state
entity_id:
- binary_sensor.330e_xdrive_connection_status
condition: []
action:
- if:
- condition: state
entity_id: device_tracker.330e_xdrive
state: home
- condition: state
entity_id: binary_sensor.330e_xdrive_connection_status
state: "on"
- condition: or
conditions:
- condition: numeric_state
entity_id: sensor.330e_xdrive_remaining_battery_percent
below: 50
- condition: numeric_state
entity_id: sensor.energyzero_today_energy_current_hour_price
below: sensor.energyzero_today_energy_average_price
then:
- service: switch.turn_on
data: {}
target:
entity_id: switch.bmw_lader
else:
- service: switch.turn_off
data: {}
target:
entity_id: switch.bmw_lader
mode: single
The following may or may not apply to your specific use case… but it’s an important concept to understand.
When using Numeric state conditions with an comparison entity ID in the above/below field, the trigger only fires based on the value of the entity listed under entity_id
. Changes to the value of the comparison entity will not trigger the automation. If the value of your comparison entity changes alot, this may cause triggers to be missed. If this is the case for your case you should switch to a template condition which will re-render on updates to either entity.