『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 1218|回复: 0

[技术探讨] 请大神们看下这个 阶梯电费的代码有什么问题

[复制链接]

4

主题

30

帖子

162

积分

注册会员

Rank: 2

积分
162
金钱
132
HASS币
0
发表于 2022-8-9 22:35:18 | 显示全部楼层 |阅读模式
我是照着这个 大神帖子里面的代码复制的  家庭用电量及电费统计模块 (Home Assistant 、Node-RED、MQTT综合应_NAS存储_什么值得买 (smzdm.com)复制后我重启就报错了   这个是哪里有问题啊?
微信图片_20220809222929.jpg


sensor:

#本月电费

- platform: template

sensors:

zong_dianfei:

value_template: >

{% set dianlian=states("sensor.tasmota_energy_total") | float %}

{% set onedianjia=0.588 %}

{% set twodianjia=0.05 %}

{% set threedianjia=0.25 %}

{% set onedianlian=200 %}

{% set twodianlian1=350 %}

{% set twodianlian2=450 %}

{% set two1month=[4,5,6,10,11,12] %}

{% if now().month in two1month %}

{% set twodianlian=twodianlian1 %}

{% else %}

{% set twodianlian=twodianlian2 %}

{% endif %}

{% if dianlian > twodianlian %}

{% set threedianfei= (dianlian - twodianlian) * threedianjia %}

{% else %}

{% set threedianfei=0 %}

{% endif %}

{% if dianlian > onedianlian %}

{% set twodianfei= (dianlian - onedianlian) * twodianjia %}

{% else %}

{% set twodianfei=0 %}

{% endif %}

{% set zong_dianfei=dianlian * onedianjia + twodianfei + threedianfei %}

{% if(zong_dianfei>0) %}

{{ zong_dianfei | round(2) }}

{% endif %}

friendly_name: 'zong_dianfei'

unit_of_measurement: "RMB"

#今日电费,本月电费-本月今天以前的电费

- platform: template

sensors:

jintian_dianfei:

value_template: >

{% set dianlian=states("sensor.tasmota_energy_total") | float %}

{% set jintiandianlian=states("sensor.tasmota_energy_today") | float %}

{% set onedianjia=0.588 %}

{% set twodianjia=0.05 %}

{% set threedianjia=0.25 %}

{% set onedianlian=200 %}

{% set twodianlian1=350 %}

{% set twodianlian2=450 %}

{% set two1month=[4,5,6,10,11,12] %}

{% if now().month in two1month %}

{% set twodianlian=twodianlian1 %}

{% else %}

{% set twodianlian=twodianlian2 %}

{% endif %}

{% if dianlian > twodianlian %}

{% set threedianfei= (dianlian - twodianlian) * threedianjia %}

{% else %}

{% set threedianfei=0 %}

{% endif %}

{% if dianlian > onedianlian %}

{% set twodianfei= (dianlian - onedianlian) * twodianjia %}

{% else %}

{% set twodianfei=0 %}

{% endif %}

{% set zongdianfei= dianlian * onedianjia + twodianfei + threedianfei %}

{% set before_dianliang= dianlian - jintiandianlian %}

{% if before_dianliang > twodianlian %}

{% set threedianfei= (before_dianliang - twodianlian) * threedianjia %}

{% else %}

{% set threedianfei=0 %}

{% endif %}

{% if before_dianliang > onedianlian %}

{% set twodianfei= (before_dianliang - onedianlian) * twodianjia %}

{% else %}

{% set twodianfei=0 %}

{% endif %}

{% set before_dianfei= before_dianliang * onedianjia + twodianfei + threedianfei %}

{% set jintian_dianfei=zongdianfei - before_dianfei %}

{% if(jintian_dianfei>0) %}

{{ jintian_dianfei | round(2) }}

{% endif %}

friendly_name: 'jintian_dianfei'

unit_of_measurement: "RMB"

#昨日电费,本月今天以前的电费-本月昨天以前的电费

- platform: template

sensors:

zuotian_dianfei:

value_template: >

{% set dianlian=states("sensor.tasmota_energy_total") | float %}

{% set jintiandianlian=states("sensor.tasmota_energy_today") | float %}

{% set zuotiandianlian=states("sensor.tasmota_energy_yesterday") | float %}

{% set onedianjia=0.588 %}

{% set twodianjia=0.05 %}

{% set threedianjia=0.25 %}

{% set onedianlian=200 %}

{% set twodianlian1=350 %}

{% set twodianlian2=450 %}

{% set two1month=[4,5,6,10,11,12] %}

{% if now().month in two1month %}

{% set twodianlian=twodianlian1 %}

{% else %}

{% set twodianlian=twodianlian2 %}

{% endif %}

{% set before_dianliang= dianlian - jintiandianlian %}

{% if before_dianliang > twodianlian %}

{% set threedianfei= (before_dianliang - twodianlian) * threedianjia %}

{% else %}

{% set threedianfei=0 %}

{% endif %}

{% if before_dianliang > onedianlian %}

{% set twodianfei= (before_dianliang - onedianlian) * twodianjia %}

{% else %}

{% set twodianfei=0 %}

{% endif %}

{% set before_dianfei= before_dianliang * onedianjia + twodianfei + threedianfei %}

{% set zuotian_before_dianliang= dianlian - jintiandianlian - zuotiandianlian %}

{% if zuotian_before_dianliang > twodianlian %}

{% set threedianfei= (zuotian_before_dianliang - twodianlian) * threedianjia %}

{% else %}

{% set threedianfei=0 %}

{% endif %}

{% if zuotian_before_dianliang > onedianlian %}

{% set twodianfei= (zuotian_before_dianliang - onedianlian) * twodianjia %}

{% else %}

{% set twodianfei=0 %}

{% endif %}

{% set zuotian_before_dianfei= zuotian_before_dianliang * onedianjia + twodianfei + threedianfei %}

{% set zuotian_dianfei = before_dianfei - zuotian_before_dianfei %}

{% if zuotian_dianfei>0 %}

{{ zuotian_dianfei | round(2) }}

{% endif %}

friendly_name: 'zuotian_dianfei'

unit_of_measurement: "RMB"

#计量清零

automation:

- id: 'monitor_clear'

alias: 月初清零电表

initial_state: true

hide_entity: false

trigger:

- platform: template

value_template: '{{ states("sensor.tasmota_energy_today") | round(3) == 0.000 }}'

condition:

- condition: template

value_template: '{{ (now().strftime("%d") | int) == 1 }}'

action:

- service: mqtt.publish

data:

topic: 'cmnd/sonoff/EnergyReset2'

payload: '0'

- service: mqtt.publish

data:

topic: 'cmnd/sonoff/EnergyReset3'

payload: '0'
这个是帖子里面的代码
这是我 这里现在的阶梯价格表
微信图片_20220809223354.jpg
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-29 02:34 , Processed in 0.226789 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表