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

标题: 家庭用电量及电费统计模块配置方法 [打印本页]

作者: FrankLv    时间: 2019-2-24 13:30
标题: 家庭用电量及电费统计模块配置方法
本帖最后由 FrankLv 于 2019-2-24 22:18 编辑

前篇
long long ago,白老板 jlxwkj 建议我上个电量计量的设备来监测下家里的用电量和计算电费,但是一直搁置未做,主要原因之一是比较懒没去折腾,另外还要动强电
但最近白老板给我做了两个电量计量设备,既然做好了那就用吧,所以索性就直接给弄上了,由于安装过程没有拍照,所以没法放了,就放白老板做好的设备吧。这货体积比较小(还有外壳哦),我家强电箱可利用空间非常非常小的情况下都可以安装上,绝对的赞。
[attach]13653[/attach]


这玩意怎么弄的我是不清楚,我也不懂,有意可以咨询白老板或者搞他现成的
说了那么多,其实我是来分享配置的。
统一回复下:我是来分享配置的,我是来分享配置的,我是来分享配置的。设备我真的不知道,这个需要问白老板,也就是群里面的懵懂的小白



配置分享:
白老板一直想让我帮忙搞定阶梯电价,由于没有设备一直就没弄,既然设备有了那就需要做配置了,配置文件可能有考虑不周全的地方,或者有更好的建议,希望大家留言回复。
分享的配置如果你要使用的话需要修改两大部分,第一个是MQTT主题,第二个是阶梯电价部分,配置中使用的是北京的阶梯电价,需要修改为您所在区域的电价。
此配置可以实现电费的阶梯计算和每月统计数据自动清零。其中电费计算值,在每个月的最后一天才用总电量判断来获取阶梯电价计算得出,其他天数利用昨日电量结合总电量和今日电量判断来获取阶梯电价计算得出。这是我目前考虑到的最完美的解决方法;自动清零功能是在每个月的1号自动运行,实现昨日电量和总电量的置0。
  1. sensor:
  2. #电压传感器
  3. - platform: mqtt
  4. name: "dianya"
  5. state_topic: "tele/electric/SENSOR"
  6. qos: 1
  7. unit_of_measurement: "V"
  8. value_template: "{{ value_json['ENERGY'].Voltage }}"
  9. #value_template: "{{ value_json.Voltage }}"

  10. #电流传感器
  11. - platform: mqtt
  12. name: "dianliu"
  13. state_topic: "tele/electric/SENSOR"
  14. qos: 1
  15. unit_of_measurement: "A"
  16. value_template: "{{ value_json['ENERGY'].Current }}"
  17. #value_template: "{{ value_json.Current }}"

  18. #功率传感器
  19. - platform: mqtt
  20. name: "gonglv"
  21. state_topic: "tele/electric/SENSOR"
  22. qos: 1
  23. unit_of_measurement: "W"
  24. value_template: "{{ value_json['ENERGY'].Power }}"
  25. #value_template: "{{ value_json.Power }}"

  26. #功率因数传感器
  27. - platform: mqtt
  28. name: "gonglvyinshu"
  29. state_topic: "tele/electric/SENSOR"
  30. qos: 1
  31. unit_of_measurement: "cosΦ"
  32. value_template: "{{ value_json['ENERGY'].Factor }}"
  33. #value_template: "{{ value_json.Factor }}"

  34. #今天用电量
  35. - platform: mqtt
  36. name: "jinri_dianliang"
  37. state_topic: "tele/electric/SENSOR"
  38. qos: 1
  39. unit_of_measurement: "kWh"
  40. value_template: "{{ value_json['ENERGY'].Today }}"
  41. #value_template: "{{ value_json.Today }}"

  42. #今日电费
  43. - platform: template
  44. sensors:
  45. jinri_dianfei:
  46. value_template: >
  47. {% if now().month in [1,3,5,7,8,10,12] %}
  48. {% set date = (31 - now().day) %}
  49. {% elif now().month in [4,6,9,11] %}
  50. {% set date = (30 - now().day) %}
  51. {% elif now().month == 2 and ((now().year-2000) % 4 > 0) %}
  52. {% set date = (28 - now().day) %}
  53. {% elif now().month == 2 and ((now().year-2000) % 4 == 0) %}
  54. {% set date = (29 - now().day) %}
  55. {% endif %}
  56. {% if (date != 0 and (states("sensor.electric") | float - states("sensor.jinri_dianliang") | float + (states("sensor.zuori_dianliang") | float * (date + 1))) | int > 400) or (date == 0 and states("sensor.electric") | int > 400) %}
  57. {{(states("sensor.jinri_dianliang") | float * 0.7783) | round(2)}}
  58. {% elif (date != 0 and (states("sensor.electric") | float - states("sensor.jinri_dianliang") | float + (states("sensor.zuori_dianliang") | float * (date + 1))) | int > 240) or (date == 0 and states("sensor.electric") | int > 240) %}
  59. {{(states("sensor.jinri_dianliang") | float * 0.5283) | round(2)}}
  60. {% else %}
  61. {{(states("sensor.jinri_dianliang") | float * 0.4783) | round(2)}}
  62. {% endif %}
  63. friendly_name: 'jinri_dianfei'
  64. unit_of_measurement: "RMB"

  65. #昨天用电量
  66. - platform: mqtt
  67. name: "zuori_dianliang"
  68. state_topic: "tele/electric/SENSOR"
  69. qos: 1
  70. unit_of_measurement: "kWh"
  71. value_template: "{{ value_json['ENERGY'].Yesterday }}"
  72. #value_template: "{{ value_json.Yesterday }}"

  73. #昨日电费
  74. - platform: template
  75. sensors:
  76. zuori_dianfei:
  77. value_template: >
  78. {% if now().month in [1,3,5,7,8,10,12] %}
  79. {% set date = (31 - now().day) %}
  80. {% elif now().month in [4,6,9,11] %}
  81. {% set date = (30 - now().day) %}
  82. {% elif now().month == 2 and ((now().year-2000) % 4 > 0) %}
  83. {% set date = (28 - now().day) %}
  84. {% elif now().month == 2 and ((now().year-2000) % 4 == 0) %}
  85. {% set date = (29 - now().day) %}
  86. {% endif %}
  87. {% if (date != 0 and (states("sensor.electric") | float - states("sensor.jinri_dianliang") | float + (states("sensor.zuori_dianliang") | float * (date + 1))) | int > 400) or (date == 0 and states("sensor.electric") | int > 400) %}
  88. {{(states("sensor.zuori_dianliang") | float * 0.7783) | round(2)}}
  89. {% elif (date != 0 and (states("sensor.electric") | float - states("sensor.jinri_dianliang") | float + (states("sensor.zuori_dianliang") | float * (date + 1))) | int > 240) or (date == 0 and states("sensor.electric") | int > 240) %}
  90. {{(states("sensor.zuori_dianliang") | float * 0.5283) | round(2)}}
  91. {% else %}
  92. {{(states("sensor.zuori_dianliang") | float * 0.4783) | round(2)}}
  93. {% endif %}
  94. friendly_name: 'zuori_dianfei'
  95. unit_of_measurement: "RMB"

  96. #总用电量
  97. - platform: mqtt
  98. name: "electric"
  99. state_topic: "tele/electric/SENSOR"
  100. qos: 1
  101. unit_of_measurement: "kWh"
  102. value_template: "{{ value_json['ENERGY'].Total }}"
  103. #value_template: "{{ value_json.Total }}"

  104. #总电费
  105. - platform: template
  106. sensors:
  107. zongdianfei:
  108. value_template: >
  109. {% if now().month in [1,3,5,7,8,10,12] %}
  110. {% set date = (31 - now().day) %}
  111. {% elif now().month in [4,6,9,11] %}
  112. {% set date = (30 - now().day) %}
  113. {% elif now().month == 2 and ((now().year-2000) % 4 > 0) %}
  114. {% set date = (28 - now().day) %}
  115. {% elif now().month == 2 and ((now().year-2000) % 4 == 0) %}
  116. {% set date = (29 - now().day) %}
  117. {% endif %}
  118. {% if (date != 0 and (states("sensor.electric") | float - states("sensor.jinri_dianliang") | float + (states("sensor.zuori_dianliang") | float * (date + 1))) | int > 400) or (date == 0 and states("sensor.electric") | int > 400) %}
  119. {{(states("sensor.electric") | float * 0.7783) | round(2)}}
  120. {% elif (date != 0 and (states("sensor.electric") | float - states("sensor.jinri_dianliang") | float + (states("sensor.zuori_dianliang") | float * (date + 1))) | int > 240) or (date == 0 and states("sensor.electric") | int > 240) %}
  121. {{(states("sensor.electric") | float * 0.5283) | round(2)}}
  122. {% else %}
  123. {{(states("sensor.electric") | float * 0.4783) | round(2)}}
  124. {% endif %}
  125. friendly_name: 'zongdianfei'
  126. unit_of_measurement: "RMB"

  127. #计量清零
  128. automation:
  129. - id: 'monitor_clear'
  130. alias: monitor_clear
  131. initial_state: true
  132. hide_entity: false
  133. trigger:
  134. # - platform: time
  135. # at: '00:00:00'
  136. - platform: template
  137. value_template: '{{ states("sensor.jinri_dianliang") | round(3) == 0.000 }}'
  138. condition:
  139. - condition: template
  140. value_template: '{{ (now().strftime("%d") | int) == 1 }}'
  141. action:
  142. - service: mqtt.publish
  143. data:
  144. topic: 'cmnd/electric/EnergyReset2'
  145. payload: '0'
  146. - service: mqtt.publish
  147. data:
  148. topic: 'cmnd/electric/EnergyReset3'
  149. payload: '0'

  150. group:
  151. electric:
  152. name: 总电量
  153. view: no
  154. entities:
  155. - sensor.dianya
  156. - sensor.dianliu
  157. - sensor.gonglv
  158. - sensor.gonglvyinshu
  159. - sensor.jinri_dianliang
  160. - sensor.jinri_dianfei
  161. - sensor.zuori_dianliang
  162. - sensor.zuori_dianfei
  163. - sensor.electric
  164. - sensor.zongdianfei
  165. - automation.monitor_clear

  166. homeassistant:
  167. customize:
  168. sensor.dianya:
  169. friendly_name: 电压
  170. icon: mdi:flash
  171. homebridge_name: 机柜电压
  172. homebridge_hidden: false

  173. sensor.dianliu:
  174. friendly_name: 电流
  175. icon: mdi:flash-auto
  176. homebridge_name: 机柜电流
  177. homebridge_hidden: false

  178. sensor.gonglv:
  179. friendly_name: 功率
  180. icon: mdi:wikipedia
  181. homebridge_name: 功率
  182. homebridge_hidden: false

  183. sensor.gonglvyinshu:
  184. friendly_name: 功率因数
  185. icon: mdi:flash-red-eye
  186. homebridge_name: 功率因数
  187. homebridge_hidden: false

  188. sensor.jinri_dianliang:
  189. friendly_name: 今日电量
  190. icon: mdi:flash
  191. homebridge_name: 今日电量
  192. homebridge_hidden: false

  193. sensor.jinri_dianfei:
  194. friendly_name: 今日电费
  195. icon: mdi:currency-cny
  196. homebridge_name: 今日电费
  197. homebridge_hidden: false

  198. sensor.zuori_dianliang:
  199. friendly_name: 昨日电量
  200. icon: mdi:flash
  201. homebridge_name: 昨日电量
  202. homebridge_hidden: false

  203. sensor.zuori_dianfei:
  204. friendly_name: 昨日电费
  205. icon: mdi:currency-cny
  206. homebridge_name: 昨日电费
  207. homebridge_hidden: false

  208. sensor.electric:
  209. friendly_name: 总电量
  210. icon: mdi:flash
  211. homebridge_name: 总电量
  212. homebridge_hidden: false

  213. sensor.zongdianfei:
  214. friendly_name: 总电费
  215. icon: mdi:currency-cny
  216. homebridge_name: 总电费
  217. homebridge_hidden: false

  218. automation.monitor_clear:
  219. friendly_name: 计量清零
  220. homebridge_name: 计量清零
  221. homebridge_hidden: false

  222. group.electric:
  223. homebridge_hidden: false
复制代码



效果展示:
使用后的效果如下:
[attach]13654[/attach]




完结!







作者: 新生活    时间: 2019-2-24 14:26
学习学习
作者: coolbug111    时间: 2019-2-24 15:17
这个感觉好实用,希望楼主分享设备的制作方法
作者: 囧    时间: 2019-2-24 15:22
厉害了白老板,lv老板!
作者: 撸大师    时间: 2019-2-24 15:27
这个设备真不错
作者: liuxiaobo    时间: 2019-2-24 15:37
henbang !很棒!

作者: FrankLv    时间: 2019-2-24 17:36
coolbug111 发表于 2019-2-24 15:17
这个感觉好实用,希望楼主分享设备的制作方法

白老板给我做的,我真不清楚,可咨询白老板,或者让他给做现成的
作者: aaa    时间: 2019-2-24 17:52
感谢分享!
作者: robotxc    时间: 2019-2-24 18:22
谢谢F大的分享,一直在用这个模块,但是原插件没有计费功能,现在终于实现了!!!
作者: lp49    时间: 2019-2-24 19:18
哪里能买到呢
作者: xuyang    时间: 2019-2-24 20:07
本帖最后由 xuyang 于 2019-2-24 20:08 编辑

0.88以后,关于阶梯电价有了专门组件,utility_meter,可以完美实现阶梯电价,每天、每周、每月、每年电量功能。
组件说明
作者: jccg315    时间: 2019-2-24 20:44
大佬,有模块改ESP01结合的图吗
作者: bfpolicemiaoxin    时间: 2019-2-24 21:15
不得了了  厉害
作者: 余歌唱晚    时间: 2019-2-24 21:24
布局很紧凑啊
作者: FrankLv    时间: 2019-2-24 22:21
本帖最后由 FrankLv 于 2019-2-24 22:25 编辑
xuyang 发表于 2019-2-24 20:07
0.88以后,关于阶梯电价有了专门组件,utility_meter,可以完美实现阶梯电价,每天、每周、每月、每年电量 ...

谢谢。了解下,固件也有部分统计了[attach]13667[/attach]

作者: hncdbai    时间: 2019-2-24 23:16
计算问题终于解决了,非常感谢
作者: honry    时间: 2019-2-25 09:11
羡慕,我的比这个大好多
作者: wqqs    时间: 2019-2-25 09:22
在哪买的啊
作者: sr-71    时间: 2019-2-25 09:47
这个是只适合自购电表吧   国电的电表都智能化了   但485上的数据全是加密的
作者: xkjstc008    时间: 2019-2-25 10:11

这个设备真不错
作者: lp49    时间: 2019-2-25 10:15
sr-71 发表于 2019-2-25 09:47
这个是只适合自购电表吧   国电的电表都智能化了   但485上的数据全是加密的 ...

我觉得这个应该是安装在家里强电箱总开关那里 和电表没有关系 直接测量总电流和电压
作者: sr-71    时间: 2019-2-25 10:27
lp49 发表于 2019-2-25 10:15
我觉得这个应该是安装在家里强电箱总开关那里 和电表没有关系 直接测量总电流和电压 ...

哦  冒失了没细看  如你所说是回路内外两种的测量模块  lz用的是感应式,黑圈就是
不错
作者: 咸味土豆    时间: 2019-2-25 11:54
大佬们真厉害,顶顶。
作者: dyldy    时间: 2019-2-25 12:07
:):):)学习学习
作者: AnyLine    时间: 2019-2-25 15:37
直接并联到电路吗?
作者: wshc1216    时间: 2019-2-25 20:24
你整套多少钱买的,
作者: skyflying5    时间: 2019-2-26 09:20
怎么引入啊?
作者: 1027590325    时间: 2019-2-26 17:56

作者: smdrv    时间: 2019-2-27 10:06
请问楼主,分时电价能不能实现?
作者: neighbour    时间: 2019-2-28 23:34
这个模块倒是很简洁。我是 计量模块55+有人modbus2wlan 198.00+ HTPC虚拟串口+ kepware+mysql+HASS 链路好长。谁让hass 的 modbus 模块不好用老师丢包。只好用了这种这种折衷的方法。
作者: iciness    时间: 2019-3-1 09:49
感谢分享!  官方有个分时计算的
作者: abel    时间: 2019-3-2 18:18
学习一下
作者: 令狐鸣    时间: 2019-3-2 19:12
这是好东西啊,求硬件模块
作者: rm6220534    时间: 2019-3-2 22:46
需要设备,哪里开车啊?
作者: kkkooo123    时间: 2019-3-5 09:48
厉害,666
作者: 上海培洁汽配    时间: 2019-3-5 13:47
很好   学习了
作者: skyflying5    时间: 2019-3-6 11:49
iciness 发表于 2019-3-1 09:49
感谢分享!  官方有个分时计算的

兄弟,官方网址在哪里啊?
作者: yh5genyn3    时间: 2019-3-7 21:04
这模块哪买
作者: mytanjing    时间: 2019-3-7 21:35
白老板那订购了一套,明天发货
作者: 57068368    时间: 2019-3-7 22:09
想跟着楼主一步一步学着来,怎么加群啊?
作者: rm6220534    时间: 2019-3-16 23:11
老大啊,配置没有缩进啊。不会用啊。
作者: flashday    时间: 2019-3-21 16:35
这个……其实每天从供电公司的掌上电力APP或者相关公众号里就能获取到准确值
作者: 85393358    时间: 2019-3-29 13:21
能不能给个.yaml文件啊 这个配置复制进去电费哪个报错 没有缩进和空格啊
作者: honry    时间: 2019-3-30 19:02
调了一下,好像没啥大问题,那个清零的我用(bu)不(hui)上(tiao)
[attach]14203[/attach]
作者: jccg315    时间: 2019-4-7 18:35
有研究过其他地区的分时,阶梯怎么写吗?

北京的是每个月阶梯电价?

上海是全年阶梯电价,好像无法定位数据,而且还分峰谷电价。
作者: 咸味土豆    时间: 2019-4-12 09:42
honry 发表于 2019-3-30 19:02
调了一下,好像没啥大问题,那个清零的我用(bu)不(hui)上(tiao)

原来有格式化好了的,谢谢分享,自动化那个这么改就可以了:

  1. automation:
  2.   - id: 'monitor_clear'
  3.     alias: monitor_clear
  4.     initial_state: true
  5.     hide_entity: false
  6.     trigger:
  7.       - platform: template
  8.         value_template: '{{ states("sensor.jinri_dianliang") | round(3) == 0.000 }}'
  9.     condition:
  10.       - condition: template
  11.         value_template: '{{ (now().strftime("%d") | int) == 1 }}'
  12.     action:
  13.       - service: mqtt.publish
  14.         data:
  15.           topic: 'cmnd/electric/EnergyReset2'
  16.           payload: '0'
  17.       - service: mqtt.publish
  18.         data:
  19.           topic: 'cmnd/electric/EnergyReset3'
  20.           payload: '0'
复制代码

作者: honry    时间: 2019-4-12 16:15
咸味土豆 发表于 2019-4-12 09:42
原来有格式化好了的,谢谢分享,自动化那个这么改就可以了:

[code]automation ...

感谢感谢
作者: oemsys    时间: 2019-5-1 13:22
咸味土豆 发表于 2019-4-12 09:42
原来有格式化好了的,谢谢分享,自动化那个这么改就可以了:

[code]automation ...

自动化还是不行,是不是还有什么须要配置?
作者: 咸味土豆    时间: 2019-5-1 15:17
oemsys 发表于 2019-5-1 13:22
自动化还是不行,是不是还有什么须要配置?

我这儿放packages里面没报错啊,最好贴个log出来,不然谁也不知道啥问题
作者: oemsys    时间: 2019-5-1 15:50
咸味土豆 发表于 2019-5-1 15:17
我这儿放packages里面没报错啊,最好贴个log出来,不然谁也不知道啥问题

配置检查
此处可以帮助你检验最新修改的配置文件有效性
配置无效
Invalid config for [automation]: required key not provided @ data['action']. Got None
required key not provided @ data['trigger']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/
作者: 咸味土豆    时间: 2019-5-1 16:03
oemsys 发表于 2019-5-1 15:50
配置检查
此处可以帮助你检验最新修改的配置文件有效性
配置无效

我这么缩进,我这儿真没问题,难道我人品好,你再好好看看格式吧。
作者: oemsys    时间: 2019-5-1 16:04
咸味土豆 发表于 2019-5-1 16:03
我这么缩进,我这儿真没问题,难道我人品好,你再好好看看格式吧。

可否把您的打包传上来?
作者: 咸味土豆    时间: 2019-5-1 16:13
oemsys 发表于 2019-5-1 16:04
可否把您的打包传上来?

[attach]15174[/attach]

我也是老了,忘了这个了,接住。

作者: oemsys    时间: 2019-5-1 17:17
咸味土豆 发表于 2019-5-1 16:13
我也是老了,忘了这个了,接住。

我了个去!!@!@什么情况!!!依旧报故障!@
作者: jyz_0501    时间: 2019-5-19 10:45
白老板 在哪??我要找他做
作者: bwtogo    时间: 2019-5-27 15:42
太太太nb了
作者: pigcais    时间: 2019-5-28 11:50
本帖最后由 pigcais 于 2019-5-31 10:37 编辑

代码的空格没有标准啊

老大能不能上传个空格正常的附件代码啊。


原来有人整理过了  

https://bbs.hassbian.com/forum.php?mod=attachment&aid=MTQyMDN8YTMzYjRjZjV8MTU1OTI3MDEwMXw1NTMxfDY0MzU%3D

作者: wk27449    时间: 2019-7-10 22:38
关于自动化部分为啥总是报错,复制的53楼土豆的。
大神给看看。
配置无效
Invalid config for [automation]: required key not provided @ data['action']. Got None
required key not provided @ data['trigger']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/
作者: yylwhy    时间: 2019-10-1 19:51
xuyang 发表于 2019-2-24 20:07
0.88以后,关于阶梯电价有了专门组件,utility_meter,可以完美实现阶梯电价,每天、每周、每月、每年电量 ...

希望大佬写个官方配置。。
作者: er_shi    时间: 2019-10-11 16:45
感谢分享!!!!!!!!!!!!!
作者: 57068368    时间: 2019-10-24 23:41
支持一下,明天改造我的这个。
作者: 57068368    时间: 2019-10-25 13:46
楼主,能给修改一下脚本嘛,我这边是按年走的阶梯电价,0-2160一个档,2161-3360一个档,3361以上一个楼,电费分别是0.52 0.57 0.82,楼主帮忙修改一下,谢谢了。
作者: menghen    时间: 2019-11-20 01:49
wk27449 发表于 2019-7-10 22:38
关于自动化部分为啥总是报错,复制的53楼土豆的。
大神给看看。
配置无效

搞定了么 我好像放进去了成功了
作者: wk27449    时间: 2019-11-21 10:05
menghen 发表于 2019-11-20 01:49
搞定了么 我好像放进去了成功了

搞定了

作者: nisofer    时间: 2019-11-21 13:36
感谢大佬分享!
作者: AnyLine    时间: 2019-12-17 17:21
你好大佬,年度阶梯价只想每年1月1执行那个清理的自动化怎么改啊?

value_template: '{{ (now().strftime("%m-%d") | int) == 1-1 }}'
这样对不对?
作者: AnyLine    时间: 2019-12-18 09:02
咸味土豆 发表于 2019-4-12 09:42
原来有格式化好了的,谢谢分享,自动化那个这么改就可以了:

土豆大神,我们是年度累计的,自动想改成每年的1月1日执行这个清理自动化,应该怎么改呢?
value_template: '{{ (now().strftime("%m-%d") | int) == 1.1 }}'
这个月写对吗?
value_template: '{{ (now().strftime("%m-%d") | int) == 1-1 }}'
不知道月日的格式啊!
作者: gldon    时间: 2020-2-16 11:14
向大神学习了
作者: skypjsfly    时间: 2020-4-24 00:55
看看。。。
作者: lxm201288    时间: 2020-4-30 20:47
学习学习
作者: winner_0986    时间: 2020-5-16 10:10
刚刚入坑,对大神膜拜
作者: 1049881009    时间: 2020-7-1 15:31
为啥代码咩有缩进,手动缩进半天,还一直报错,现在还没搞定
作者: Raines    时间: 2020-7-2 15:17
好強大....感謝樓主分享~我收下了XD
作者: a4610759    时间: 2020-8-9 23:31
很强大,但是大佬可否把缩进加上,您这样让我这样的小白情何以堪。。。
作者: azfyl1987    时间: 2020-8-17 19:12
想问一下,在那里购买呢
作者: chenggangyaan    时间: 2020-8-21 15:12
楼主,你好,我现在能正常监测各种数据,但是发现就是用电量不准确,无论是今日、昨日、还是总的,感觉都不对,请问是怎么回事呢,感觉比真实用量少了至少10倍


作者: 郑凯强    时间: 2020-8-23 15:10
楼主的效果图敷衍的很啊
作者: HHHhhhH    时间: 2020-8-23 16:13
感谢楼主分享
作者: zybzhong    时间: 2021-1-26 19:20
大佬用的那么久,白大佬出来露露脸,我也买个来。想买找不到源
作者: zgp0126    时间: 2021-6-11 09:21
怎么联系下白老板呢?
作者: tane    时间: 2021-10-17 23:56
本帖最后由 tane 于 2021-10-18 00:09 编辑

楼主的阶梯电费计算有点问题。现在把我的计算方法共享一下。

  1.   
  2. sensor:  
  3. #本月用电量
  4.   - platform: mqtt
  5.     name: "zong"
  6.     state_topic: "tele/sonoff/SENSOR"
  7.     value_template: "{{value_json['ENERGY'].Total }}"
  8.     unit_of_measurement: "KWH"
  9. #昨天用电量
  10.   - platform: mqtt
  11.     name: "zuotian"
  12.     state_topic: "tele/sonoff/SENSOR"
  13.     value_template: "{{value_json['ENERGY'].Yesterday }}"
  14.     unit_of_measurement: "KWH"
  15. #今天用电量
  16.   - platform: mqtt
  17.     name: "jintian"
  18.     state_topic: "tele/sonoff/SENSOR"
  19.     value_template: "{{value_json['ENERGY'].Today }}"
  20.     unit_of_measurement: "KWH"
  21. #功率
  22.   - platform: mqtt
  23.     name: "gonglv"
  24.     state_topic: "tele/sonoff/SENSOR"
  25.     value_template: "{{value_json['ENERGY'].Power }}"
  26.     unit_of_measurement: "W"
  27. #功率因数
  28.   - platform: mqtt
  29.     name: "yinshu"
  30.     state_topic: "tele/sonoff/SENSOR"
  31.     value_template: "{{value_json['ENERGY'].Factor }}"
  32.     unit_of_measurement: "cosΦ"
  33. #电压
  34.   - platform: mqtt
  35.     name: "dianya"
  36.     state_topic: "tele/sonoff/SENSOR"
  37.     value_template: "{{value_json['ENERGY'].Voltage }}"
  38.     unit_of_measurement: "V"
  39. #电流
  40.   - platform: mqtt
  41.     name: "dianliu"
  42.     state_topic: "tele/sonoff/SENSOR"
  43.     value_template: "{{value_json['ENERGY'].Current }}"
  44.     unit_of_measurement: "A"
  45.    
  46. #本月电费
  47.   - platform: template
  48.     sensors:
  49.       zong_dianfei:
  50.         value_template: >
  51.           {% set onedianjia=0.588 %}
  52.           {% set twodianjia=0.05 %}
  53.           {% set threedianjia=0.25 %}
  54.           {% set onedianlian=200 %}
  55.           {% set twodianlian1=350 %}
  56.           {% set twodianlian2=450 %}
  57.           {% set two1month=[4,5,6,10,11,12] %}
  58.           {% if now().month in two1month %}
  59.           {% set twodianlian=twodianlian1 %}
  60.           {% else %}
  61.           {% set twodianlian=twodianlian2 %}
  62.           {% endif %}
  63.           {% if states("sensor.zong") | float > twodianlian %}
  64.           {% set threedianfei= (states("sensor.zong") | float - twodianlian) * threedianjia %}
  65.           {% else %}
  66.           {% set threedianfei=0 %}
  67.           {% endif %}
  68.           {% if states("sensor.zong") | float > onedianlian %}
  69.           {% set twodianfei= (states("sensor.zong") | float - onedianlian) * twodianjia %}
  70.           {% else %}
  71.           {% set twodianfei=0 %}
  72.           {% endif %}
  73.           {{ (states("sensor.zong") | float * onedianjia  + twodianfei + threedianfei) | round(2) }}
  74.          
  75.         friendly_name: 'zong_dianfei'
  76.         unit_of_measurement: "RMB"
  77.    
  78. #今日电费,本月电费-本月今天以前的电费
  79.   - platform: template
  80.     sensors:
  81.       jintian_dianfei:
  82.         value_template: >
  83.           {% set onedianjia=0.588 %}
  84.           {% set twodianjia=0.05 %}
  85.           {% set threedianjia=0.25 %}
  86.           {% set onedianlian=200 %}
  87.           {% set twodianlian1=350 %}
  88.           {% set twodianlian2=450 %}
  89.           {% set two1month=[4,5,6,10,11,12] %}
  90.           {% if now().month in two1month %}
  91.           {% set twodianlian=twodianlian1 %}
  92.           {% else %}
  93.           {% set twodianlian=twodianlian2 %}
  94.           {% endif %}
  95.           {% if states("sensor.zong") | float > twodianlian %}
  96.           {% set threedianfei= (states("sensor.zong") | float - twodianlian) * threedianjia %}
  97.           {% else %}
  98.           {% set threedianfei=0 %}
  99.           {% endif %}
  100.           {% if states("sensor.zong") | float > onedianlian %}
  101.           {% set twodianfei= (states("sensor.zong") | float - onedianlian) * twodianjia %}
  102.           {% else %}
  103.           {% set twodianfei=0 %}
  104.           {% endif %}
  105.           {% set zongdianfei= states("sensor.zong") | float * onedianjia  + twodianfei + threedianfei %}
  106.           {% set before_dianliang= states("sensor.zong") | float - states("sensor.jintian") | float %}
  107.           {% if before_dianliang > twodianlian %}
  108.           {% set threedianfei= (before_dianliang - twodianlian) * threedianjia %}
  109.           {% else %}
  110.           {% set threedianfei=0 %}
  111.           {% endif %}
  112.           {% if before_dianliang > onedianlian %}
  113.           {% set twodianfei= (before_dianliang - onedianlian) * twodianjia %}
  114.           {% else %}
  115.           {% set twodianfei=0 %}
  116.           {% endif %}
  117.           {% set before_dianfei= before_dianliang * onedianjia  + twodianfei + threedianfei %}
  118.           {{ (zongdianfei - before_dianfei) | round(2) }}
  119.          
  120.         friendly_name: 'jintian_dianfei'
  121.         unit_of_measurement: "RMB"
  122.    
  123. #昨日电费,本月今天以前的电费-本月昨天以前的电费
  124.   - platform: template
  125.     sensors:
  126.       zuotian_dianfei:
  127.         value_template: >
  128.           {% set onedianjia=0.588 %}
  129.           {% set twodianjia=0.05 %}
  130.           {% set threedianjia=0.25 %}
  131.           {% set onedianlian=200 %}
  132.           {% set twodianlian1=350 %}
  133.           {% set twodianlian2=450 %}
  134.           {% set two1month=[4,5,6,10,11,12] %}
  135.           {% if now().month in two1month %}
  136.           {% set twodianlian=twodianlian1 %}
  137.           {% else %}
  138.           {% set twodianlian=twodianlian2 %}
  139.           {% endif %}
  140.           {% set before_dianliang= states("sensor.zong") | float - states("sensor.jintian") | float %}
  141.           {% if before_dianliang > twodianlian %}
  142.           {% set threedianfei= (before_dianliang - twodianlian) * threedianjia %}
  143.           {% else %}
  144.           {% set threedianfei=0 %}
  145.           {% endif %}
  146.           {% if before_dianliang > onedianlian %}
  147.           {% set twodianfei= (before_dianliang - onedianlian) * twodianjia %}
  148.           {% else %}
  149.           {% set twodianfei=0 %}
  150.           {% endif %}
  151.           {% set before_dianfei= before_dianliang * onedianjia  + twodianfei + threedianfei %}
  152.           {% set zuotian_before_dianliang= states("sensor.zong") | float - states("sensor.jintian") | float - states("sensor.zuotian") | float %}
  153.           {% if zuotian_before_dianliang > twodianlian %}
  154.           {% set threedianfei= (zuotian_before_dianliang - twodianlian) * threedianjia %}
  155.           {% else %}
  156.           {% set threedianfei=0 %}
  157.           {% endif %}
  158.           {% if zuotian_before_dianliang > onedianlian %}
  159.           {% set twodianfei= (zuotian_before_dianliang - onedianlian) * twodianjia %}
  160.           {% else %}
  161.           {% set twodianfei=0 %}
  162.           {% endif %}
  163.           {% set zuotian_before_dianfei= zuotian_before_dianliang * onedianjia  + twodianfei + threedianfei %}
  164.           {{ (before_dianfei - zuotian_before_dianfei) | round(2) }}
  165.          
  166.         friendly_name: 'zuotian_dianfei'
  167.         unit_of_measurement: "RMB"
  168.         
  169.         
  170.         
  171.         
  172.         
  173.         
  174. #计量清零
  175. automation:
  176.   - id: 'monitor_clear'
  177.     alias: 月初清零电表
  178.     initial_state: true
  179.     hide_entity: false
  180.     trigger:
  181.       - platform: template
  182.         value_template: '{{ states("sensor.jintian") | round(3) == 0.000 }}'
  183.     condition:
  184.       - condition: template
  185.         value_template: '{{ (now().strftime("%d") | int) == 1 }}'
  186.     action:
  187.       - service: mqtt.publish
  188.         data:
  189.           topic: 'cmnd/electric/EnergyReset2'
  190.           payload: '0'
  191.       - service: mqtt.publish
  192.         data:
  193.           topic: 'cmnd/electric/EnergyReset3'
  194.           payload: '0'
复制代码



作者: tane    时间: 2021-10-18 00:03
其中0.588为基础电费,0.05二档电价和一档电价的差值,0.25为三档电价和二档电价和差值。
湖南省的二三阶电量分为春秋和夏冬两个不同的时节,4,5,6,10,11,12这几个月为春秋季,二阶电量为200度到350度,三阶电量为350度以上。其它月为夏冬季,二阶电量为200度到450度,三阶电量为450度以上。
作者: tane    时间: 2021-10-18 00:17
本帖最后由 tane 于 2021-10-18 00:25 编辑

再发一个nodeRED的流程,每天早上9点自动发送本月和昨天的用电信息到企业微信


  1. [
  2.     {
  3.         "id": "1d46653.604e69b",
  4.         "type": "tab",
  5.         "label": "流程1",
  6.         "disabled": false,
  7.         "info": ""
  8.     },
  9.     {
  10.         "id": "f893ac1f8aad8c04",
  11.         "type": "inject",
  12.         "z": "1d46653.604e69b",
  13.         "name": "每天9点发送用电信息",
  14.         "props": [
  15.             {
  16.                 "p": "payload"
  17.             },
  18.             {
  19.                 "p": "topic",
  20.                 "vt": "str"
  21.             }
  22.         ],
  23.         "repeat": "",
  24.         "crontab": "00 09 * * *",
  25.         "once": false,
  26.         "onceDelay": 0.1,
  27.         "topic": "",
  28.         "payloadType": "date",
  29.         "x": 180,
  30.         "y": 300,
  31.         "wires": [
  32.             [
  33.                 "7591564a577ec462",
  34.                 "5deba9b47876cdbc",
  35.                 "bccbc0133730c976",
  36.                 "97b6d13c343b7466"
  37.             ]
  38.         ]
  39.     },
  40.     {
  41.         "id": "7591564a577ec462",
  42.         "type": "api-current-state",
  43.         "z": "1d46653.604e69b",
  44.         "name": "昨天用电量",
  45.         "server": "e8349c19021c66e6",
  46.         "version": 2,
  47.         "outputs": 1,
  48.         "halt_if": "",
  49.         "halt_if_type": "num",
  50.         "halt_if_compare": "is",
  51.         "entity_id": "sensor.zuotian",
  52.         "state_type": "num",
  53.         "blockInputOverrides": false,
  54.         "outputProperties": [
  55.             {
  56.                 "property": "payload1",
  57.                 "propertyType": "msg",
  58.                 "value": "",
  59.                 "valueType": "entityState"
  60.             },
  61.             {
  62.                 "property": "data1",
  63.                 "propertyType": "msg",
  64.                 "value": "",
  65.                 "valueType": "entity"
  66.             }
  67.         ],
  68.         "override_topic": false,
  69.         "state_location": "payload",
  70.         "override_payload": "msg",
  71.         "entity_location": "data",
  72.         "override_data": "msg",
  73.         "x": 410,
  74.         "y": 240,
  75.         "wires": [
  76.             [
  77.                 "751e2708c33ced2c"
  78.             ]
  79.         ]
  80.     },
  81.     {
  82.         "id": "c680952d07579b39",
  83.         "type": "function",
  84.         "z": "1d46653.604e69b",
  85.         "name": "",
  86.         "func": "\nvar desc='本月已用电量:'+ msg.payload[2] + 'KWH\\r\\n';\ndesc+='本月已用电费:'+ msg.payload[3] + '元\\r\\n';\ndesc+='昨天用电量:'+ msg.payload[0] + 'KWH\\r\\n';\ndesc+='昨天电费:'+ msg.payload[1] + '元';\n\nwechat = {\n    'touser' : '@all',\n    'msgtype': 'textcard',\n    'textcard': {\n        'title': '家庭用电详情',\n        'description' : desc,\n        'url' : `http://你的hass地址:9080`,\n        'btntxt':'查看详情',\n    },\n}\n\nmsg.payload = {};\nmsg.payload = wechat;\n\nreturn msg;",
  87.         "outputs": 1,
  88.         "noerr": 0,
  89.         "initialize": "",
  90.         "finalize": "",
  91.         "libs": [],
  92.         "x": 1070,
  93.         "y": 300,
  94.         "wires": [
  95.             [
  96.                 "eb48db2366f3d619"
  97.             ]
  98.         ]
  99.     },
  100.     {
  101.         "id": "eb48db2366f3d619",
  102.         "type": "bizwechat-push",
  103.         "z": "1d46653.604e69b",
  104.         "name": "",
  105.         "bizwechat": "c36787cd99e1d359",
  106.         "x": 1200,
  107.         "y": 300,
  108.         "wires": [
  109.             []
  110.         ]
  111.     },
  112.     {
  113.         "id": "5deba9b47876cdbc",
  114.         "type": "api-current-state",
  115.         "z": "1d46653.604e69b",
  116.         "name": "昨天电费",
  117.         "server": "e8349c19021c66e6",
  118.         "version": 2,
  119.         "outputs": 1,
  120.         "halt_if": "",
  121.         "halt_if_type": "str",
  122.         "halt_if_compare": "is",
  123.         "entity_id": "sensor.zuotian_dianfei",
  124.         "state_type": "num",
  125.         "blockInputOverrides": false,
  126.         "outputProperties": [
  127.             {
  128.                 "property": "payload2",
  129.                 "propertyType": "msg",
  130.                 "value": "",
  131.                 "valueType": "entityState"
  132.             },
  133.             {
  134.                 "property": "data2",
  135.                 "propertyType": "msg",
  136.                 "value": "",
  137.                 "valueType": "entity"
  138.             }
  139.         ],
  140.         "override_topic": false,
  141.         "state_location": "payload",
  142.         "override_payload": "msg",
  143.         "entity_location": "data",
  144.         "override_data": "msg",
  145.         "x": 400,
  146.         "y": 280,
  147.         "wires": [
  148.             [
  149.                 "751e2708c33ced2c"
  150.             ]
  151.         ]
  152.     },
  153.     {
  154.         "id": "bccbc0133730c976",
  155.         "type": "api-current-state",
  156.         "z": "1d46653.604e69b",
  157.         "name": "本月已用电量",
  158.         "server": "e8349c19021c66e6",
  159.         "version": 2,
  160.         "outputs": 1,
  161.         "halt_if": "",
  162.         "halt_if_type": "str",
  163.         "halt_if_compare": "is",
  164.         "entity_id": "sensor.zong",
  165.         "state_type": "num",
  166.         "blockInputOverrides": false,
  167.         "outputProperties": [
  168.             {
  169.                 "property": "payload3",
  170.                 "propertyType": "msg",
  171.                 "value": "",
  172.                 "valueType": "entityState"
  173.             },
  174.             {
  175.                 "property": "data3",
  176.                 "propertyType": "msg",
  177.                 "value": "",
  178.                 "valueType": "entity"
  179.             }
  180.         ],
  181.         "override_topic": false,
  182.         "state_location": "payload",
  183.         "override_payload": "msg",
  184.         "entity_location": "data",
  185.         "override_data": "msg",
  186.         "x": 420,
  187.         "y": 320,
  188.         "wires": [
  189.             [
  190.                 "751e2708c33ced2c"
  191.             ]
  192.         ]
  193.     },
  194.     {
  195.         "id": "97b6d13c343b7466",
  196.         "type": "api-current-state",
  197.         "z": "1d46653.604e69b",
  198.         "name": "本月已用电费",
  199.         "server": "e8349c19021c66e6",
  200.         "version": 2,
  201.         "outputs": 1,
  202.         "halt_if": "",
  203.         "halt_if_type": "str",
  204.         "halt_if_compare": "is",
  205.         "entity_id": "sensor.zong_dianfei",
  206.         "state_type": "num",
  207.         "blockInputOverrides": false,
  208.         "outputProperties": [
  209.             {
  210.                 "property": "payload4",
  211.                 "propertyType": "msg",
  212.                 "value": "",
  213.                 "valueType": "entityState"
  214.             },
  215.             {
  216.                 "property": "data4",
  217.                 "propertyType": "msg",
  218.                 "value": "",
  219.                 "valueType": "entity"
  220.             }
  221.         ],
  222.         "override_topic": false,
  223.         "state_location": "payload",
  224.         "override_payload": "msg",
  225.         "entity_location": "data",
  226.         "override_data": "msg",
  227.         "x": 420,
  228.         "y": 360,
  229.         "wires": [
  230.             [
  231.                 "751e2708c33ced2c"
  232.             ]
  233.         ]
  234.     },
  235.     {
  236.         "id": "dbd29a142dd582dd",
  237.         "type": "debug",
  238.         "z": "1d46653.604e69b",
  239.         "name": "",
  240.         "active": true,
  241.         "tosidebar": true,
  242.         "console": true,
  243.         "tostatus": true,
  244.         "complete": "payload",
  245.         "targetType": "msg",
  246.         "statusVal": "payload",
  247.         "statusType": "auto",
  248.         "x": 1220,
  249.         "y": 180,
  250.         "wires": []
  251.     },
  252.     {
  253.         "id": "3070750dc82bb153",
  254.         "type": "join",
  255.         "z": "1d46653.604e69b",
  256.         "name": "合并成数组",
  257.         "mode": "custom",
  258.         "build": "array",
  259.         "property": "payload",
  260.         "propertyType": "msg",
  261.         "key": "topic",
  262.         "joiner": "\\n",
  263.         "joinerType": "str",
  264.         "accumulate": false,
  265.         "timeout": "",
  266.         "count": "4",
  267.         "reduceRight": false,
  268.         "reduceExp": "",
  269.         "reduceInit": "",
  270.         "reduceInitType": "",
  271.         "reduceFixup": "",
  272.         "x": 750,
  273.         "y": 300,
  274.         "wires": [
  275.             [
  276.                 "68ea1d77a313e3b3",
  277.                 "1ea592885261c0c0"
  278.             ]
  279.         ]
  280.     },
  281.     {
  282.         "id": "751e2708c33ced2c",
  283.         "type": "function",
  284.         "z": "1d46653.604e69b",
  285.         "name": "合并",
  286.         "func": "\nreturn { payload:[msg.payload1, msg.payload2,msg.payload3,msg.payload4]};\n",
  287.         "outputs": 1,
  288.         "noerr": 0,
  289.         "initialize": "",
  290.         "finalize": "",
  291.         "libs": [],
  292.         "x": 610,
  293.         "y": 300,
  294.         "wires": [
  295.             [
  296.                 "3070750dc82bb153"
  297.             ]
  298.         ]
  299.     },
  300.     {
  301.         "id": "68ea1d77a313e3b3",
  302.         "type": "debug",
  303.         "z": "1d46653.604e69b",
  304.         "name": "",
  305.         "active": true,
  306.         "tosidebar": true,
  307.         "console": true,
  308.         "tostatus": true,
  309.         "complete": "payload",
  310.         "targetType": "msg",
  311.         "statusVal": "payload",
  312.         "statusType": "auto",
  313.         "x": 1100,
  314.         "y": 420,
  315.         "wires": []
  316.     },
  317.     {
  318.         "id": "1ea592885261c0c0",
  319.         "type": "function",
  320.         "z": "1d46653.604e69b",
  321.         "name": "合并成一个数组",
  322.         "func": "var redata=[0,0,0,0]\nfor (var x in msg.payload)\n{\n    var data=msg.payload[x];\n    for(var i =0;i<redata.length;i++){\n        if(data.length>=i-1 && data[i] && data[i]>0){\n            redata[i]=data[i];\n        }\n    }\n}\nreturn { payload:redata};\n",
  323.         "outputs": 1,
  324.         "noerr": 0,
  325.         "initialize": "",
  326.         "finalize": "",
  327.         "libs": [],
  328.         "x": 920,
  329.         "y": 300,
  330.         "wires": [
  331.             [
  332.                 "dbd29a142dd582dd",
  333.                 "c680952d07579b39"
  334.             ]
  335.         ]
  336.     },
  337.     {
  338.         "id": "e8349c19021c66e6",
  339.         "type": "server",
  340.         "name": "Home Assistant",
  341.         "version": 1,
  342.         "legacy": false,
  343.         "addon": false,
  344.         "rejectUnauthorizedCerts": true,
  345.         "ha_boolean": "y|yes|true|on|home|open",
  346.         "connectionDelay": true,
  347.         "cacheJson": true
  348.     },
  349.     {
  350.         "id": "c36787cd99e1d359",
  351.         "type": "bizwechat-configurator",
  352.         "name": "企业微信推送",
  353.         "port": "3001",
  354.         "corpid": "",
  355.         "agentid": "",
  356.         "corpsecret": "",
  357.         "url": "",
  358.         "token": "",
  359.         "aeskey": "",
  360.         "client_id": "",
  361.         "client_secret": ""
  362.     }
  363. ]
复制代码





作者: ericbox    时间: 2022-2-2 08:57
不知道和国网电表比准确性能不能达到90%  众所周知国网的表都快5%-8
作者: tsyj99    时间: 2022-2-19 19:32
tane 发表于 2021-10-17 23:56
楼主的阶梯电费计算有点问题。现在把我的计算方法共享一下。

老哥,按您的代码来,出现这个错误是什么意思?

作者: mattshy    时间: 2022-2-22 10:43
真好,学习学习

作者: mattshy    时间: 2022-2-22 10:45
怎么才能联系到白老板?我也想搞一套

作者: mattshy    时间: 2022-2-22 10:58
现在还可以联系到白老板买一套吗?

作者: lzmit    时间: 2022-9-6 21:53
学习一下
作者: Ari    时间: 2022-9-26 13:46
tane 发表于 2021-10-18 00:03
其中0.588为基础电费,0.05二档电价和一档电价的差值,0.25为三档电价和二档电价和差值。
湖南省的二三阶电 ...

你好兄弟,我这边不分春夏秋冬,也就是一年都是一个价,怎么把春秋季和夏冬季删掉呢?另外还想要个今月电量和上月电量。今月电费和上月电费能帮忙写下嘛,小白一个
作者: cyrusle    时间: 2022-10-5 22:47
学习学习
作者: a592861135    时间: 2022-10-9 10:47
大神厉害了
作者: qiqisw    时间: 2022-10-17 22:36
感谢分享!!!!!
作者: nbxzl    时间: 2022-11-11 13:56
xuyang 发表于 2019-2-24 20:07
0.88以后,关于阶梯电价有了专门组件,utility_meter,可以完美实现阶梯电价,每天、每周、每月、每年电量 ...

学习了

作者: feifei006    时间: 2023-1-9 10:28
厉害了白老板

作者: jeromeli    时间: 2023-2-27 16:14
模块哪有卖的???多少钱一共?
作者: accpxyz    时间: 2023-2-28 00:09
感谢分享!
作者: daedalus    时间: 2023-3-3 00:00
tane 发表于 2021-10-17 23:56
楼主的阶梯电费计算有点问题。现在把我的计算方法共享一下。

为什么月初清零无法触发?
作者: 琅琊    时间: 2023-4-4 01:48
homeassisstant接受数据了,一看数据不对,然后我把tasmota模块的计数重置,导致现在能源统计是负数,怎么重置一下?求大神指导
作者: cyl1995    时间: 2023-12-4 11:30
111111111111111111111111111111




欢迎光临 『瀚思彼岸』» 智能家居技术论坛 (https://bbs.hassbian.com/) Powered by Discuz! X3.5