How to define trigger time value programmatically

I have an electric blanket, controlled by a simple RF socket switch (rfx-PT2262). Using the switch node, I can match "msg.bri==1" to a trigger set to 1 hour, and "msg.bri==2" to a trigger set to 2 hours, etc.

This way I can say "Alexa set blanket to 2" and it will come on for 2 hours.

It works fine. (NB the reset power thing is because the blanket automatically turns itself off, while the mains power stays on, so it was necessary to send a mains OFF and 1s delay before turning it on each time. Also necessary to reset the trigger timers in case someone tries to turn it on and it's already on.)

I'd like to simplify this to have a single trigger that uses an incoming message to define how long the trigger lasts. Is there such a thing?

Might be an idea to post your code.

You may want to look at the switch node with the change node - should do what you want.

Craig

Here is an example of a small part of one of my flows that demonstrates the use of those two nodes together

[{"id":"2c93b1f2.9ead7e","type":"link in","z":"6865126d.1bde1c","name":"Link from Tank Level Reading","links":["e4b56095.308b","8d27a951.83a4a8"],"x":35,"y":340,"wires":[["3d5ca2c3.eaedce"]]},{"id":"4e92428d.fdaabc","type":"change","z":"6865126d.1bde1c","name":"Enable Schedule","rules":[{"t":"set","p":"payload","pt":"msg","to":"suspended false","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":340,"wires":[["7d8236d1.3c4ac8","622beeec.f0cef"]]},{"id":"3d5ca2c3.eaedce","type":"switch","z":"6865126d.1bde1c","name":"Check for Water level","property":"payload","propertyType":"msg","rules":[{"t":"lte","v":"25","vt":"num"},{"t":"gt","v":"35","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":160,"y":340,"wires":[["4e92428d.fdaabc"],["d4f08431.e0baf8"]]},{"id":"d4f08431.e0baf8","type":"change","z":"6865126d.1bde1c","name":"Disable Schedule","rules":[{"t":"set","p":"payload","pt":"msg","to":"suspended true","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":380,"wires":[["7d8236d1.3c4ac8","d1a04747.dd1b28"]]},{"id":"622beeec.f0cef","type":"debug","z":"6865126d.1bde1c","name":"Enable","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","x":610,"y":340,"wires":[]},{"id":"d1a04747.dd1b28","type":"debug","z":"6865126d.1bde1c","name":"Disable","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","x":600,"y":400,"wires":[]},{"id":"2cbb6c5c.8e80d4","type":"comment","z":"6865126d.1bde1c","name":"Keep Water Tank Level between 25% and 35% be enabling/disabling the schedule","info":"","x":330,"y":300,"wires":[]}]

regards

Craig

Thanks Craig, apologies if you posted just before I completely re-wrote my post!

I figured out how to do the first part of my original question (resetting triggers etc.), now I just need to know how to change the timer value in Trigger node dynamically. I am already using switch and change nodes to achieve most of the function so far...

Sorry should have said more - just on the run on the way out

Have a look at Ncherrys MyTimeout node - you should be able to use it to control your variable timeouts and send whatever output you need to the wall outlet

It would probably be simpler to move the wall outlet to a sonoff style device that supports MQTT directly

Craig

And here is the use of the MyTimeoutNode and feeding it some data to vary its run time

[{"id":"6ea69ec4.cfb7c","type":"ui_button","z":"a78930fe.ed232","name":"Manual 8hr Turn on of Circulating Pump","group":"2b345d73.f4d042","order":3,"width":0,"height":0,"passthru":false,"label":"Manual CP 8 Hr Turn on","color":"","bgcolor":"","icon":"","payload":"{     \"payload\": \"on\",     \"timeout\": 28800,     \"warning\": 5 }","payloadType":"json","topic":"topic/circulatingpumpoverride","x":220,"y":780,"wires":[["a3177923.ca0018"]]},{"id":"868c3c0f.4264d","type":"mqtt out","z":"a78930fe.ed232","name":"","topic":"topic/circulatingpumpoverride","qos":"","retain":"","broker":"389dd264.7716de","x":940,"y":900,"wires":[]},{"id":"da81147e.1b8758","type":"inject","z":"a78930fe.ed232","name":"Turn off CP Override","topic":"topic/circulatingpumpoverride","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":170,"y":940,"wires":[["a3177923.ca0018"]]},{"id":"45112e1b.eb1e7","type":"ui_button","z":"a78930fe.ed232","name":"Manual 4hr Turn on of Circulating Pump","group":"2b345d73.f4d042","order":2,"width":0,"height":0,"passthru":false,"label":"Manual CP 4 Hr Turn on","color":"","bgcolor":"","icon":"","payload":"{     \"payload\": \"on\",     \"timeout\": 14400,     \"warning\": 5 }","payloadType":"json","topic":"topic/circulatingpumpoverride","x":220,"y":820,"wires":[["a3177923.ca0018"]]},{"id":"467580d3.350e2","type":"ui_button","z":"a78930fe.ed232","name":"Turn off Manual Override of CP","group":"2b345d73.f4d042","order":4,"width":0,"height":0,"passthru":false,"label":"Turn off Manual Override of CP","color":"","bgcolor":"","icon":"","payload":"0","payloadType":"str","topic":"topic/circulatingpumpoverride","x":190,"y":900,"wires":[["a3177923.ca0018"]]},{"id":"a3177923.ca0018","type":"mytimeout","z":"a78930fe.ed232","name":"Circulatiing Pump Manual Turn on","outtopic":"topic/circulatingpumpoverride","outsafe":"1","outwarning":"","outunsafe":"0","warning":"5","timer":"3600","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":640,"y":860,"wires":[["868c3c0f.4264d","7e21acd2.904284"],["8511d477.998b38","e516bdb2.36da9"]]},{"id":"b6dc0aa1.e05c68","type":"ui_button","z":"a78930fe.ed232","name":"Manual 2hr Turn on of Circulating Pump","group":"2b345d73.f4d042","order":1,"width":0,"height":0,"passthru":false,"label":"Manual CP 2 Hr Turn on","color":"","bgcolor":"","icon":"","payload":"{     \"payload\": \"on\",     \"timeout\": 7200,     \"warning\": 5 }","payloadType":"json","topic":"topic/circulatingpumpoverride","x":220,"y":860,"wires":[["a3177923.ca0018"]]},{"id":"7e21acd2.904284","type":"debug","z":"a78930fe.ed232","name":"CP Fire up - Node 1","active":false,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","x":920,"y":860,"wires":[]},{"id":"8511d477.998b38","type":"debug","z":"a78930fe.ed232","name":"CP Fire up - Node 2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":920,"y":960,"wires":[]},{"id":"e516bdb2.36da9","type":"change","z":"a78930fe.ed232","name":"Set Variable to get it onto Dashboard","rules":[{"t":"set","p":"CIrculatingPumpTimeToRun","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":1020,"wires":[["caf1a13f.d8d6"]]},{"id":"caf1a13f.d8d6","type":"change","z":"a78930fe.ed232","name":"Take Variable and Put into Payload","rules":[{"t":"move","p":"CIrculatingPumpTimeToRun","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":1080,"wires":[["d5602c1e.081f4"]]},{"id":"d5602c1e.081f4","type":"ui_text_input","z":"a78930fe.ed232","name":"","label":"Manual Pump - Time to run (Sec)","group":"2b345d73.f4d042","order":0,"width":0,"height":0,"passthru":true,"mode":"text","delay":300,"topic":"","x":960,"y":1080,"wires":[[]]},{"id":"2b345d73.f4d042","type":"ui_group","z":"","name":"Circulating Pump Control","tab":"c9d53e06.a95c8","order":4,"disp":true,"width":"5"},{"id":"389dd264.7716de","type":"mqtt-broker","z":"a78930fe.ed232","broker":"localhost","port":"1883","clientid":"Node-Red","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c9d53e06.a95c8","type":"ui_tab","z":"","name":"CURTIN house main page","icon":"dashboard","order":1}]

regards
Craig

A lot of your code could be replaced with variables.

Where the SWITCH NODE is, you get the value you then reference in the TRIGGER NODE.

Then replace the SWITCH NODE with a FUNCTION NODE that sends a message with the properties needed to set the delay time used in the trigger node.

(Been off line for a while/time. Still getting back up to speed.)
If you post the flow, I can have a look.

But it will need something to simulate the BLANKET NODE output.