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

 找回密码
 立即注册
楼主: tangxingjie1991

[新奇玩法] 我也来个电费插件(RN流)-浙江

  [复制链接]

25

主题

441

帖子

2338

积分

论坛积极会员

积分
2338
金钱
1897
HASS币
0
发表于 2021-7-14 16:37:39 | 显示全部楼层
zzc2 发表于 2021-7-14 11:01
调试了一下,好像把计算模块里的playload改成data就好了

谢谢 终于好了 不过电费算的不对
回复

使用道具 举报

0

主题

98

帖子

564

积分

高级会员

Rank: 4

积分
564
金钱
466
HASS币
0
发表于 2021-7-14 16:46:59 | 显示全部楼层
13857781577 发表于 2021-7-14 16:37
谢谢 终于好了 不过电费算的不对

电费也要调整一点代码。
在计算月度电费
var fu = 0;
var su = 0;
var tu = 0;

这三行下方加一条
msg.monthused = msg.data.state;
回复

使用道具 举报

1

主题

111

帖子

550

积分

高级会员

Rank: 4

积分
550
金钱
439
HASS币
0
发表于 2021-7-15 16:24:34 | 显示全部楼层
可以搞下广东吗
回复

使用道具 举报

25

主题

441

帖子

2338

积分

论坛积极会员

积分
2338
金钱
1897
HASS币
0
发表于 2021-7-16 10:22:10 | 显示全部楼层
zzc2 发表于 2021-7-14 16:46
电费也要调整一点代码。
在计算月度电费

谢谢 终于可以了 楼主 三个阶梯数据哪来的?
回复

使用道具 举报

0

主题

98

帖子

564

积分

高级会员

Rank: 4

积分
564
金钱
466
HASS币
0
发表于 2021-7-16 10:56:00 | 显示全部楼层
13857781577 发表于 2021-7-16 10:22
谢谢 终于可以了 楼主 三个阶梯数据哪来的?

哪个数据啊?这些不都是api获取的么。三阶梯的电价是手动设置的。
回复

使用道具 举报

0

主题

37

帖子

348

积分

中级会员

Rank: 3Rank: 3

积分
348
金钱
311
HASS币
0
发表于 2021-7-16 14:38:54 | 显示全部楼层
bao2000bao 发表于 2021-6-28 16:25
河北的我也没抓到,完全看不懂

关注河北的朋友,
回复

使用道具 举报

44

主题

632

帖子

3560

积分

论坛元老

Rank: 8Rank: 8

积分
3560
金钱
2928
HASS币
0
发表于 2021-7-27 00:59:28 | 显示全部楼层
楼主请把3个剃度用电怎么设置的配置文件上传或者过程说明下吧 大家都需要这个
回复

使用道具 举报

0

主题

98

帖子

564

积分

高级会员

Rank: 4

积分
564
金钱
466
HASS币
0
发表于 2021-7-27 14:27:59 | 显示全部楼层
本帖最后由 zzc2 于 2021-7-27 14:33 编辑

阶梯用电计算


[{"id":"38074e40.591192","type":"tab","label":"流程4","disabled":false,"info":""},{"id":"8f371818.f4c0e8","type":"api-current-state","z":"38074e40.591192","name":"获取月度用电","server":"a21ccefa.edc7e","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.monthelectricity","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data_month","override_data":"msg","blockInputOverrides":false,"x":320,"y":300,"wires":[["a1d9172b.9e23e8"]]},{"id":"a1d9172b.9e23e8","type":"api-current-state","z":"38074e40.591192","name":"获取年度用电","server":"a21ccefa.edc7e","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.yearelectricity","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data_year","override_data":"msg","blockInputOverrides":false,"x":580,"y":300,"wires":[["b22ce339.d3c9c"]]},{"id":"b22ce339.d3c9c","type":"function","z":"38074e40.591192","name":"计算阶梯用电","func":"let fup = 0;\nlet sup = 0;\nlet tu = 0;\nlet month_used = msg.data_month.attributes.f+msg.data_month.attributes.g;\nif(msg.data_year.attributes.firstused==msg.data_year.attributes.firsttotal){\n    fup = 100;\n}else if((msg.data_year.attributes.firstused+month_used)>=msg.data_year.attributes.firsttotal){\n    fup = 100;\n    month_used = msg.data_year.attributes.firsttotal-Number(msg.data_year.attributes.firstused);\n}else{\n    fup = (msg.data_year.attributes.firstused+month_used)/msg.data_year.attributes.firsttotal;\n    month_used = 0;\n}\n\nif(msg.data_year.attributes.secondused==msg.data_year.attributes.secondtotal){\n    sup = 100;\n}else if((msg.data_year.attributes.secondused+month_used)>=msg.data_year.attributes.secondtotal){\n    sup = 100;\n    month_used = msg.data_year.attributes.secondtotal-msg.data_year.attributes.secondused;\n}else{\n    sup = (((msg.data_year.attributes.secondused+month_used))/Number(msg.data_year.attributes.secondtotal));\n    month_used = 0;\n}\n\nif(month_used>0){\n    tu = month_used;\n}\n\nmsg.fup = fup;\nmsg.sup = sup;\nmsg.tu = tu;\n\n\n\nmsg.payload = null;\n\nreturn msg;","outputs":1,"noerr":0,"x":960,"y":300,"wires":[["3631a5d7.06c3da","6c3024de.9a75fc","42863031.ccb23"]]},{"id":"b11f9546.23b168","type":"inject","z":"38074e40.591192","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"02 07 * * *","once":false,"onceDelay":0.1,"x":100,"y":300,"wires":[["8f371818.f4c0e8"]]},{"id":"6c3024de.9a75fc","type":"ha-entity","z":"38074e40.591192","name":"第一阶梯用电","server":"a21ccefa.edc7e","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"electricity_first"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"%"}],"state":"fup","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1340,"y":300,"wires":[[]]},{"id":"3631a5d7.06c3da","type":"ha-entity","z":"38074e40.591192","name":"第二阶梯用电","server":"a21ccefa.edc7e","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"electricity_second"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"%"}],"state":"sup","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1340,"y":360,"wires":[[]]},{"id":"42863031.ccb23","type":"ha-entity","z":"38074e40.591192","name":"第三阶梯用电","server":"a21ccefa.edc7e","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"electricity_third"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"度"}],"state":"tu","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1340,"y":420,"wires":[[]]},{"id":"a21ccefa.edc7e","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]


注意:
我这里把本月的用电量也加到阶梯用电里了,不确定会不会有问题,有问题的话请自行修改计算那里的代码吧
回复

使用道具 举报

44

主题

632

帖子

3560

积分

论坛元老

Rank: 8Rank: 8

积分
3560
金钱
2928
HASS币
0
发表于 2021-7-27 20:55:13 | 显示全部楼层

函数提示 TypeError: Cannot read property 'attributes' of undefined
请问老乡怎么改 我比较小白 请明文详细点说下怎么修改你说的代码
回复

使用道具 举报

44

主题

632

帖子

3560

积分

论坛元老

Rank: 8Rank: 8

积分
3560
金钱
2928
HASS币
0
发表于 2021-7-27 23:32:09 | 显示全部楼层

搞定了,没用你这个帖子里发的代码直接提取,而是按照你私信发我的配置文件代码OK了,哈哈哈
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-25 15:45 , Processed in 0.055473 second(s), 30 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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