这个是算出来的,先搞个 input_datetime 设置为宝宝的出生日期,
- platform: template
sensors:
baobao_age:
unit_of_measurement: '月'
friendly_name: '年龄'
value_template: >-
{% set today=as_timestamp(now()) %}
{% set birthday=state_attr('input_datetime.birthday', 'timestamp') | int %}
{{ ((today - birthday) / 86400 / 30) | round(1) }}
搞个这个,但是这个不能自动更新宝宝的年龄,所以还要加一个触发器
- alias: 'age_update'
trigger:
- platform: state
entity_id: sensor.time
action:
- service: homeassistant.update_entity
entity_id: sensor.baobao_age
这样就大功告成了 |