具有功能节点和继电器的节点红色温度传感器

时间:2018-05-09 13:15:39

标签: javascript node-red home-automation

我想使用连接到Raspberri Pi的DS18b20探头来控制空调。 我让继电器在我想要的正确温度下开启和关闭。 下一步是我在努力的地方...... 我的要求: 关闭空调< = 20(这是有效的) 打开空调> = 25(这可行) 当空调开启25以上......保持空调开启直到20,然后关闭(这我不能工作) 当空调关闭时,等待10分钟{以保护电机}(这我无法工作)

我尝试过使用带有以下代码的函数节点:

image of code

任何帮助都非常感谢...我已经尝试过切换和更换节点,但我可以;让延迟部分工作,或者让它继续冷却到20。

1 个答案:

答案 0 :(得分:1)

因此,为了使其工作,您需要流上下文变量来存储状态。我为您的问题创建了以下示例流程,它使用了以下两个上下文变量:

  • aircon_is_on :是一个布尔值,表示空调当前是否已开启或关闭。
  • aircon_last_switch_tms :是空调最后一次打开或关闭的时间戳(以1970年以来的毫秒数表示)。

enter image description here

您可以在下面找到该流程的详细信息。

[{"id":"cc99810d.fdcb8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"16703345.888dcd","type":"inject","z":"cc99810d.fdcb8","name":"initialisation at startup","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":180,"y":80,"wires":[["97135670.acdd88"]]},{"id":"97135670.acdd88","type":"change","z":"cc99810d.fdcb8","name":"initialize flow variables","rules":[{"t":"set","p":"aircon_is_on","pt":"flow","to":"false","tot":"bool"},{"t":"set","p":"aircon_last_switch_tms","pt":"flow","to":"0","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":80,"wires":[[]]},{"id":"3f26e3af.245a1c","type":"inject","z":"cc99810d.fdcb8","name":"","topic":"","payload":"19","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":200,"wires":[["cd981b11.6bac88"]]},{"id":"d7ffb888.3cd648","type":"comment","z":"cc99810d.fdcb8","name":"inject nodes simulating the DS18b20 sensor output","info":"","x":210,"y":140,"wires":[]},{"id":"d0544032.848e","type":"inject","z":"cc99810d.fdcb8","name":"","topic":"","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":240,"wires":[["cd981b11.6bac88"]]},{"id":"995c2849.57d9f8","type":"inject","z":"cc99810d.fdcb8","name":"","topic":"","payload":"21","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":280,"wires":[["cd981b11.6bac88"]]},{"id":"f6cee931.a62e78","type":"inject","z":"cc99810d.fdcb8","name":"","topic":"","payload":"24","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":320,"wires":[["cd981b11.6bac88"]]},{"id":"3dcf7adb.db0d66","type":"inject","z":"cc99810d.fdcb8","name":"","topic":"","payload":"25","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":360,"wires":[["cd981b11.6bac88"]]},{"id":"76d055f9.3878dc","type":"inject","z":"cc99810d.fdcb8","name":"","topic":"","payload":"26","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":400,"wires":[["cd981b11.6bac88"]]},{"id":"7698406b.1ca73","type":"change","z":"cc99810d.fdcb8","name":"set flow context and payload to switch off aircon","rules":[{"t":"set","p":"aircon_is_on","pt":"flow","to":"false","tot":"bool"},{"t":"set","p":"aircon_last_switch_tms","pt":"flow","to":"","tot":"date"},{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":220,"wires":[["7d3fbf47.1bc7a"]]},{"id":"cd981b11.6bac88","type":"switch","z":"cc99810d.fdcb8","name":"aircon is on ?","property":"aircon_is_on","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":300,"wires":[["ea9a6fa9.67ae5"],["fc9c4632.967d78"]]},{"id":"ea9a6fa9.67ae5","type":"switch","z":"cc99810d.fdcb8","name":"temp <= 20 ?","property":"payload","propertyType":"msg","rules":[{"t":"lte","v":"20","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":510,"y":220,"wires":[["7698406b.1ca73"]]},{"id":"7d3fbf47.1bc7a","type":"debug","z":"cc99810d.fdcb8","name":"aircon command to switch it on / off","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1400,"y":280,"wires":[]},{"id":"fc9c4632.967d78","type":"switch","z":"cc99810d.fdcb8","name":"temp >= 25 ?","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"25","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":510,"y":320,"wires":[["78c00f1f.7f943"]]},{"id":"78c00f1f.7f943","type":"switch","z":"cc99810d.fdcb8","name":"switch on / off more than 10 minutes ago ?","property":"($toMillis($now())-$flowContext(\"aircon_last_switch_tms\")) > (10*60*1000)","propertyType":"jsonata","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":700,"y":380,"wires":[["c5c075a6.a039b8"]]},{"id":"c5c075a6.a039b8","type":"change","z":"cc99810d.fdcb8","name":"set flow context and payload to switch off aircon","rules":[{"t":"set","p":"aircon_is_on","pt":"flow","to":"true","tot":"bool"},{"t":"set","p":"aircon_last_switch_tms","pt":"flow","to":"","tot":"date"},{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":380,"wires":[["7d3fbf47.1bc7a"]]},{"id":"a8acfa78.442cd8","type":"debug","z":"cc99810d.fdcb8","name":"flow.aircon_last_switch_tms  (in milli seconds since 1970)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":730,"y":540,"wires":[]},{"id":"e6dec5ed.6e6d78","type":"inject","z":"cc99810d.fdcb8","name":"flow.aircon_last_switch_tms","topic":"","payload":"aircon_last_switch_tms","payloadType":"flow","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":540,"wires":[["a8acfa78.442cd8","b8c55cf8.7f1fe"]]},{"id":"2a2df95.069e206","type":"debug","z":"cc99810d.fdcb8","name":"flow.aircon_last_switch_tms","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":640,"y":600,"wires":[]},{"id":"b8c55cf8.7f1fe","type":"change","z":"cc99810d.fdcb8","name":"$fromMillis(payload)","rules":[{"t":"set","p":"payload","pt":"msg","to":"$fromMillis(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":600,"wires":[["2a2df95.069e206"]]},{"id":"ff677399.2c529","type":"comment","z":"cc99810d.fdcb8","name":"test nodes to check the aircon flow context variables","info":"","x":227,"y":462,"wires":[]},{"id":"4a49b01b.1db3","type":"inject","z":"cc99810d.fdcb8","name":"","topic":"","payload":"aircon_is_on","payloadType":"flow","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":169,"y":499,"wires":[["2497d1be.1155ce"]]},{"id":"2497d1be.1155ce","type":"debug","z":"cc99810d.fdcb8","name":"flow.aircon_is_on","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":610,"y":500,"wires":[]},{"id":"14796044.a8c56","type":"comment","z":"cc99810d.fdcb8","name":"output to switch on /off aircon","info":"","x":1360,"y":100,"wires":[]},{"id":"3411ff23.37aa1","type":"comment","z":"cc99810d.fdcb8","name":"aircon flow context variables","info":"This flow makes use of 2 flow context variables:\n1. *aircon_is_on* : is a boolean indicating if the aircon is currently switched on or off.\n2. *aircon_last_switch_tms* : is a timestamp (expressed in number of milli seconds since 1970) of the last time the aircon has been switch on or off.","x":453,"y":26,"wires":[]}]

KR 扬