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

 找回密码
 立即注册
查看: 17623|回复: 15

[流程系列] 写了一个洗衣机洗完通知耗电和时间(修正bug 可以导入了)

[复制链接]

66

主题

779

帖子

4407

积分

论坛元老

Rank: 8Rank: 8

积分
4407
金钱
3623
HASS币
20
发表于 2021-3-19 11:20:14 | 显示全部楼层 |阅读模式
本帖最后由 guitengyue 于 2022-5-26 15:19 编辑

刚刚搬入新家,女王说家里洗衣机太少,于是购入了两个壁挂式洗衣机,顺便拿了一个DC1作为接线板
于是想到利用实时功率和总功率,做了一个自动化,实现:洗完通知,并告知用时,用电情况 (这里有几个小插曲,女王觉得洗衣机费电,于是这个自动化可以知道每次洗用了多少电,然后第一版通知后,她每次问我这次洗了多久,于是索性弄了一个时间差
[{"id":"82f5ba1.7686448","type":"server-state-changed","z":"4048e7e6.356be8","name":"洗衣机总功率<9","server":"5bb02c99.614f64","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.dc1_xiyiji_power","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"9","halt_if_type":"num","halt_if_compare":"lt","outputs":2,"output_only_on_state_change":true,"for":"60","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":170,"y":520,"wires":[["8bf8cc6c.2baeb"],[]]},{"id":"5bb02c99.614f64","type":"server","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]


评分

参与人数 1金钱 +2 收起 理由
lloydan + 2 感谢楼主分享!

查看全部评分

回复

使用道具 举报

66

主题

779

帖子

4407

积分

论坛元老

Rank: 8Rank: 8

积分
4407
金钱
3623
HASS币
20
 楼主| 发表于 2021-3-19 11:22:24 | 显示全部楼层
当时几个小坑:
1. nodered的通知语法。。。
2. ios的app推送,设置的时候要fq
3. var xxx = flow.get('xxx',xxx) xxx要一致。。。
这几条弄了半天
回复

使用道具 举报

16

主题

223

帖子

1868

积分

金牌会员

Rank: 6Rank: 6

积分
1868
金钱
1645
HASS币
0
发表于 2021-3-19 18:09:49 | 显示全部楼层
我导入不了

微信图片_20210214004257.png
回复

使用道具 举报

33

主题

2196

帖子

5838

积分

论坛元老

Rank: 8Rank: 8

积分
5838
金钱
3642
HASS币
60
QQ
发表于 2021-3-19 22:57:41 | 显示全部楼层
膜拜大神。
我不生产技术,我只是技术的搬运工。
回复

使用道具 举报

66

主题

779

帖子

4407

积分

论坛元老

Rank: 8Rank: 8

积分
4407
金钱
3623
HASS币
20
 楼主| 发表于 2021-3-20 17:02:22 | 显示全部楼层

最近论坛好像有问题?
我前几天添加别人的代码也出现这个问题,但是我用复制到软件看了下,都是好的啊
回复

使用道具 举报

4

主题

91

帖子

687

积分

高级会员

Rank: 4

积分
687
金钱
596
HASS币
0
发表于 2021-3-27 16:01:59 | 显示全部楼层
同样导入不了
回复

使用道具 举报

22

主题

319

帖子

3925

积分

论坛元老

Rank: 8Rank: 8

积分
3925
金钱
3601
HASS币
30
发表于 2021-3-27 20:39:41 | 显示全部楼层
QQ截图20210327203805.png

同样问题,楼主或者用在线json检查一下!
回复

使用道具 举报

66

主题

779

帖子

4407

积分

论坛元老

Rank: 8Rank: 8

积分
4407
金钱
3623
HASS币
20
 楼主| 发表于 2021-3-29 23:23:39 | 显示全部楼层
MX10085 发表于 2021-3-27 20:39
同样问题,楼主或者用在线json检查一下!

我不知道啥情况啊
我复制别人的也添加不进去。。
也是提示这个错误,难道mac出问题了么
回复

使用道具 举报

13

主题

220

帖子

644

积分

高级会员

Rank: 4

积分
644
金钱
422
HASS币
0
发表于 2021-9-12 11:14:12 | 显示全部楼层
guitengyue 发表于 2021-3-29 23:23
我不知道啥情况啊
我复制别人的也添加不进去。。
也是提示这个错误,难道mac出问题了么 ...

直接丢附件不会有这个问题
回复

使用道具 举报

66

主题

779

帖子

4407

积分

论坛元老

Rank: 8Rank: 8

积分
4407
金钱
3623
HASS币
20
 楼主| 发表于 2021-9-13 13:43:40 | 显示全部楼层
zhouhui920 发表于 2021-9-12 11:14
直接丢附件不会有这个问题
[{"id":"4048e7e6.356be8","type":"tab","label":"洗衣机洗完通知","disabled":false,"info":""},{"id":"26d8b700.53d95a","type":"api-call-service","z":"4048e7e6.356be8","name":"通知所有手机","server":"5bb02c99.614f64","version":1,"debugenabled":false,"service_domain":"notify","service":"notify","entityId":"","data":"{"title":"洗衣机","message":"衣服洗完,本次消耗{{{flow.end}}}度,用时{{{flow.xhtime}}}"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1380,"y":560,"wires":[[]]},{"id":"82f5ba1.7686448","type":"server-state-changed","z":"4048e7e6.356be8","name":"洗衣机总功率<9","server":"5bb02c99.614f64","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.dc1_xiyiji_power","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"9","halt_if_type":"num","halt_if_compare":"lt","outputs":2,"output_only_on_state_change":true,"for":"60","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":180,"y":520,"wires":[["8bf8cc6c.2baeb"],[]]},{"id":"b60c1b32.41b608","type":"server-state-changed","z":"4048e7e6.356be8","name":"洗衣机总功玑�>30","server":"5bb02c99.614f64","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.dc1_xiyiji_power","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"30","halt_if_type":"num","halt_if_compare":"gt","outputs":2,"output_only_on_state_change":true,"for":"5","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":120,"y":380,"wires":[["e334d597.529908"],[]]},{"id":"8bf8cc6c.2baeb","type":"switch","z":"4048e7e6.356be8","name":"","property":"xyj","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":370,"y":520,"wires":[["384b6575.78898a","45aa1499.9a302c"],[]]},{"id":"9eb8269.34ac4d8","type":"change","z":"4048e7e6.356be8","name":"设定xyj=1","rules":[{"t":"set","p":"xyj","pt":"flow","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":380,"wires":[[]]},{"id":"384b6575.78898a","type":"change","z":"4048e7e6.356be8","name":"设定xyj=0","rules":[{"t":"set","p":"xyj","pt":"flow","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":620,"wires":[[]]},{"id":"10e54243.7a95be","type":"api-call-service","z":"4048e7e6.356be8","name":"只通知我的手机","server":"5bb02c99.614f64","version":1,"debugenabled":false,"service_domain":"notify","service":"mobile_app_tengyuede_iphone","entityId":"","data":"{"title":"洗衣机","message":"衣服洗完,本次消耗{{{flow.end}}}度,用时{{{flow.xhtime}}}"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1400,"y":480,"wires":[[]]},{"id":"e334d597.529908","type":"switch","z":"4048e7e6.356be8","name":"","property":"xyj","propertyType":"flow","rules":[{"t":"neq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":380,"wires":[["9eb8269.34ac4d8","a81653d6.39fd2","c25687cb.3a98f8"],[]],"info":"xyj=0的时候,且功率触发》30,记录当前电表读数"},{"id":"a1d3aea4.62ad9","type":"function","z":"4048e7e6.356be8","name":"计算能耗","func":"var start = flow.get('start',start);\nvar finish = flow.get('finish',finish);\nvar dianneng = finish - start;\nmsg.payload = dianneng.toFixed(2);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":800,"y":540,"wires":[["6282f71f.1b0a38"]]},{"id":"a81653d6.39fd2","type":"api-current-state","z":"4048e7e6.356be8","name":"记录开始洗电能","server":"5bb02c99.614f64","version":1,"outputs":2,"halt_if":"0","halt_if_type":"num","halt_if_compare":"is_not","override_topic":true,"entity_id":"sensor.dc1_xiyiji_total","state_type":"num","state_location":"start","override_payload":"flow","entity_location":"data","override_data":"msg","blockInputOverrides":true,"x":500,"y":440,"wires":[[],[]]},{"id":"45aa1499.9a302c","type":"api-current-state","z":"4048e7e6.356be8","name":"记录结束电能","server":"5bb02c99.614f64","version":1,"outputs":2,"halt_if":"0","halt_if_type":"num","halt_if_compare":"is_not","override_topic":true,"entity_id":"sensor.dc1_xiyiji_total","state_type":"num","state_location":"finish","override_payload":"flow","entity_location":"data","override_data":"msg","blockInputOverrides":true,"x":580,"y":520,"wires":[["a1d3aea4.62ad9","488104ff.80f39c"],[]]},{"id":"6282f71f.1b0a38","type":"change","z":"4048e7e6.356be8","name":"转移数据","rules":[{"t":"move","p":"payload","pt":"msg","to":"end","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":480,"wires":[["5cff32a1.b2cfcc"]]},{"id":"c25687cb.3a98f8","type":"function","z":"4048e7e6.356be8","name":"获取开始时间","func":"var date = new Date();\nmsg.payload = date;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":320,"wires":[["f5b322aa.d8512"]]},{"id":"f5b322aa.d8512","type":"change","z":"4048e7e6.356be8","name":"转移数据","rules":[{"t":"move","p":"payload","pt":"msg","to":"timestart","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":280,"wires":[[]]},{"id":"488104ff.80f39c","type":"function","z":"4048e7e6.356be8","name":"计算消耗时间","func":"var nowdate = new Date();\nvar timestart = flow.get('timestart',timestart);\nvar difftime = (nowdate - timestart)/1000;\nvar hours = parseInt(difftime/3600);    // 小时 60*60 总小时数-过去的小时数=现在的小时数 \nvar minutes = parseInt(difftime%3600/60); // 分钟 -(day*24) 以60秒丽�一敨�份 取余 剩下秒数 秒数/60 就是分钟数\nvar seconds = parseInt(difftime%60);  // 以60秒为一整份 取余 剩下秒数\nmsg.payload = hours+"h"+minutes+"min";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":800,"y":600,"wires":[["44f9d7f4.526478"]]},{"id":"44f9d7f4.526478","type":"change","z":"4048e7e6.356be8","name":"转移数据","rules":[{"t":"move","p":"payload","pt":"msg","to":"xhtime","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":980,"y":640,"wires":[[]]},{"id":"5cff32a1.b2cfcc","type":"stoptimer","z":"4048e7e6.356be8","duration":"5","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":1160,"y":480,"wires":[["26d8b700.53d95a"],[]]},{"id":"5bb02c99.614f64","type":"server","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
这样可以了嘛
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-22 03:37 , Processed in 0.157448 second(s), 36 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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