本帖最后由 dscao 于 2023-6-19 00:58 编辑
template:
- sensor:
- name: electricity_last_date_entity_jiandan
unique_id: electricity_last_date_entity_jiandan
state: >
{% set now = as_timestamp(now()) %}
{% set last_updated = as_timestamp(states('sensor.electricity_last_date_entity')) %}
{% set diff = (now - last_updated) / 86400 %}
{% if diff < 1 %}
今天
{% elif 1 <= diff < 2 %}
昨天
{% elif 2 <= diff < 3 %}
前天
{% elif 3 <= diff < 4 %}
大前天
{% else %}
未知
{% endif %}
- trigger:
- platform: event
event_type: "state_changed"
event_data:
entity_id: sensor.electricity_95598
sensor:
- name: electricity_charge_balance_entity
unique_id: electricity_charge_balance_entity
state: "{{ states('sensor.electricity_95598') }}"
unit_of_measurement: "CNY"
device_class: monetary
- name: electricity_balance_is_pay_entity
unique_id: electricity_balance_is_pay_entity
state: "{{ state_attr('sensor.electricity_95598', 'is_pay') }}"
- name: last_electricity_usage_entity
unique_id: last_electricity_usage_entity
state: "{{ state_attr('sensor.electricity_95598', 'last_electricity_usage') }}"
state_class: measurement
unit_of_measurement: "kWh"
- name: yearly_electricity_usage_entity
unique_id: yearly_electricity_usage_entity
state: "{{ state_attr('sensor.electricity_95598', 'yearly_electricity_usage') }}"
state_class: measurement
unit_of_measurement: "kWh"
- name: yearly_electricity_charge_entity
unique_id: yearly_electricity_charge_entity
state: "{{ state_attr('sensor.electricity_95598', 'yearly_electricity_charge') }}"
unit_of_measurement: "CNY"
device_class: monetary
- name: electricity_need_pay_3406665807552
unique_id: electricity_need_pay_3406665807552
state: "{{ state_attr('sensor.electricity_95598', 'need_pay') }}"
unit_of_measurement: "CNY"
device_class: monetary
- name: thismonth_electricity_usage_entity
unique_id: thismonth_electricity_usage_entity
state: "{{ state_attr('sensor.electricity_95598', 'thismonth_electricity_usage') }}"
state_class: measurement
unit_of_measurement: "kWh"
- name: electricity_last_date_entity
unique_id: electricity_last_date_entity
state: "{{ state_attr('sensor.electricity_95598', 'last_date') }}"
|