This is a Testing Version with minutes of iphone battery being lower than 50, resetting until it goes under it again. In the original its days since vacuum robot level has fallen under 50. To get a integer of how many days its been since it has cleaned basically.
So i think i almost got it about working, when i paste the template into the template checker i get this error:
TypeError: ‘<’ not supported between instances of ‘str’ and ‘int’
My code in config.yaml is:
- platform: template
sensors:
minutes_since_iphone_battery_low:
friendly_name: Minutes Since iPhone Battery Low
unit_of_measurement: minutes
value_template: >
{% if states.sensor.pp_iphone_battery_level.state < 50 %}
{% set now = as_timestamp(now()) %}
{% set pp_iphone_low_battery_time = states.sensor.pp_iphone_low_battery_time.state %}
{% set pp_iphone_low_battery_time = as_timestamp(pp_iphone_low_battery_time) %}
{% set minutes_since_iphone_battery_low = (now - pp_iphone_low_battery_time) // 60 %}
{{ minutes_since_iphone_battery_low }}
{% else %}
0
{% endif %}
I setup the datetime helper which seems to be working since the automation is successfully writing to it
alias: Update iphone low battery time
description: ""
trigger:
- platform: state
entity_id:
- sensor.pp_iphone_battery_level
to: "50"
from: "51"
condition: []
action:
- service: input_datetime.set_datetime
data:
time: "{{ now().strftime(\"%H:%M\") }}"
target:
entity_id: input_datetime.pp_iphone_low_battery_time
mode: single
When i look at the history of the sensor i created in the config it doesn’t get updated. So i the issue has to be in the Template. Anyway if anyone could help me out.
i know this is kind of old but i’m hoping someone can point me in the right direction or give me some guidance…
{{ expand(‘group.birthdays’) | selectattr(‘attributes.countdown’, ‘lt’, ‘30’) | list }}
TypeError: ‘<’ not supported between instances of ‘int’ and ‘str’
i’m not sure why… the countdown attribute within each of the sensors is a numeric value… and i’m going to do more work with this but for some reason it’s erroring already and i can’t understand why…
so for instance i’ll have a sensor, we’ll call it ‘sensor.dad’
the state is the ‘year-month-day’ of their birthday and the attributes are templated to create the age and a countdown to their birthday
sensor.birthday_dad
state=1979-08-29
friendly_name: Birthday Dad
age: 44
countdown: 16