I am fairly new to node-red but have had a lot of success with it so far with thermostats, thermometers and my esp8266/mqtt garage door controller.
I want to implement in NR this logic: "At 9pm every night, if the garage door is open, close it and email me that I forgot".
I would like to try to do this using native NR components as much as possible, and avoiding use of Flow or Globabl context memory.
If I was writing this using a RESTful api for my opener/controller, it would look simply something like this:
// 9pm triggered through a scheduler
if ( get_garage_door_state() == OPEN )
set_garage_door_state( CLOSED)
Below is what I have so far, trying to use a Trigger node. It works at 9pm but the problem is since I also receive state messages from the controller at various times throughoutt the rest of the day and it re-closes the door throughout the day
I have a couple' ideas but they get pretty messy so I wonder if there is a style or approach that I am overlooking. Thoughts?
First time to try this export function so I hope this works:
[{"id":"b2e3b511.840318","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"3e7ab128.7e8ce6","type":"trigger","z":"b2e3b511.840318","op1":"","op2":"close","op1type":"nul","op2type":"str","duration":"10","extend":false,"units":"s","reset":"close","bytopic":"all","name":"If door is not closed within 10 seconds","x":494,"y":211,"wires":[["1578fa93.951035","bac45e27.c94a88"]]},{"id":"19e8bf8.f2bc7c1","type":"inject","z":"b2e3b511.840318","name":"Every night at 9pm","topic":"","payload":"query","payloadType":"str","repeat":"","crontab":"00 21 * * *","once":false,"onceDelay":0.1,"x":153,"y":127,"wires":[["315a43e7.84109c","3e7ab128.7e8ce6"]]},{"id":"315a43e7.84109c","type":"mqtt out","z":"b2e3b511.840318","name":"MQTT request the door state","topic":"pv/garage/door/cmd","qos":"","retain":"","broker":"bbd15021.27a95","x":471,"y":128,"wires":[]},{"id":"35235003.de4628","type":"mqtt in","z":"b2e3b511.840318","name":"MQTT door state open or closed","topic":"pv/garage/door/state","qos":"0","broker":"bbd15021.27a95","x":142,"y":210,"wires":[["3e7ab128.7e8ce6"]]},{"id":"cf2cffe6.ccbd88","type":"comment","z":"b2e3b511.840318","name":"Every night close the garage door if left open","info":"door controller mqtt is\n\nemits:\n- pv/garage/door/state open\n- pv/garage/door/state close\n\nresponds to commands:\n- pv/garage/door/cmd open\n- pv/garage/door/cmd close\n- pv/garage/door/cmd query\n\n\n","x":191,"y":38,"wires":[]},{"id":"1578fa93.951035","type":"debug","z":"b2e3b511.840318","name":"MQTT close the door (simulated)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":868,"y":212,"wires":[]},{"id":"bac45e27.c94a88","type":"debug","z":"b2e3b511.840318","name":"Email me \"You Forgot!\" (simulated)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":870,"y":283,"wires":[]},{"id":"bbd15021.27a95","type":"mqtt-broker","z":"","name":"Clopi MqBroker","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
The garage controller message api is listed in the comment. I think I could enhance that api with "you-should-be-closed-now" command with a "but-I-wasnt-closed" message in response, but for now I am trying to learn some specific NR lessons here.
Thanks!
John