Need some help with a varable JSON

Hi,

i want to use the slider to set a timer with the time i sent with the slider ...

can someone show me how to set the the "template" that the "timeout" is variable.

Thanks in advance

Felix

[{"id":"64c3829f.e20b0c","type":"template","z":"a8bf081a.d902a8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n    \"payload\": \"on\",\n    \"timeout\": 600,\n    \"warning\": 30\n}","output":"str","x":1040,"y":1440,"wires":[["12bc1a2b.f14556"]]},{"id":"a69f9cf.900056","type":"inject","z":"a8bf081a.d902a8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":840,"y":1440,"wires":[["64c3829f.e20b0c"]]},{"id":"d57e0c8.ee019f","type":"debug","z":"a8bf081a.d902a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1490,"y":1440,"wires":[]},{"id":"12bc1a2b.f14556","type":"mytimeout","z":"a8bf081a.d902a8","name":"","outtopic":"furz","outsafe":"on","outwarning":"Warning","outunsafe":"off","warning":"5","timer":"30","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":1230,"y":1440,"wires":[["d57e0c8.ee019f"],["d57e0c8.ee019f"]]},{"id":"c8f6e35b.1f088","type":"ui_slider","z":"a8bf081a.d902a8","name":"","label":"slider","tooltip":"","group":"b80d8471.95b3c8","order":2,"width":0,"height":0,"passthru":false,"outs":"end","topic":"","min":"1","max":"60","step":1,"x":830,"y":1380,"wires":[["64c3829f.e20b0c"]]},{"id":"b80d8471.95b3c8","type":"ui_group","z":"","name":"Ipsum","tab":"4104eaec.2c7e24","disp":false,"width":"6","collapse":false},{"id":"4104eaec.2c7e24","type":"ui_tab","z":"","name":"Sandbox","icon":"dashboard","order":9,"disabled":false,"hidden":false}]

sorry... something went wrong by copy. now it is correct

What type is the timeout node, it is not one of the standard ones? Possibly it is node-red-contrib-something.

... if you know any other way to control a countdown with "slider" output you´re welcome.

that´s the one i thaught it´s the easiest. Maybe there´s something which is easier.

actually it´s the node-red-contrib-mytimeout node

in my case it´s okay to know how to set the "timeout number" in the template node with the slider output, because this will control the node-red-contrib-mytimeout node

You still haven't told us what type the node is, without that we don't know how you are trying to do it.
However, f you are just trying to get the value of payload into the timeout attribute you want

{
    "payload": "on",
    "timeout": {{payload}},
    "warning": 30
}
1 Like

That´s it !!!

sorry for my confused description ... your solution works perfekt.

Thank you very much

Are you sure that you want it as a json string, not as an object like this, using a Change node?

[{"id":"ac74f434.b8d2d","type":"inject","z":"514a90a5.c7bae8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":116,"y":1169,"wires":[["4ad4619e.fe888"]]},{"id":"bc1262b5.14af8","type":"debug","z":"514a90a5.c7bae8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":499,"y":1170,"wires":[]},{"id":"4ad4619e.fe888","type":"change","z":"514a90a5.c7bae8","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"timeout","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"},{"t":"set","p":"warning","pt":"msg","to":"30","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":309,"y":1169,"wires":[["bc1262b5.14af8"]]}]

no. it´s also a good idea, but i need only to set the time output from a slider node which is set at the Dashboard.

So you solved my problem with your last answer. Thx.

I would be interested to know why you want it in a json string rather than a javascript object, if you don't mind saying.

Because of the description of the node I want to control:

That is very unusual for the node to expect a JSON string rather than a javascript object. Is that really correct?

That's what it's written in the description of the node ... I'm not able to say why.

When I asked if it is correct I suppose I meant does it work passing in the string?

@Colin I saw the issue you created, I fear the worst. See this part of the code

Most of the rest of the parsing is regex based too.

Yuk
@Flixm Personally I wouldn't use a node that requires the data in this form.

Yeah, and the code is full with TODO and FIXME comments about how it is better to replace the entire thing with an actual state machine. Which made me think that you might be able to replace this node with node-red-contrib-dsm instead:

@Flixm unless you need to change the timeout setting dynamically then the built in Trigger node may well be able to do what you want.

I raised an issue on the nodes github page asking for clarification on this, and it appears the author is not clear on the difference between JSON (which is a string) and javascript objects. I attempted to help him/her but am not completely certain I succeeded. However, it appears that the node does not require JSON at all but works fine with normal objects with attributes.

Colin has pointed out my errors in the documentation and I'll try to get them updated tonight (thanks Colin). Sorry for the confusion. The preferred method is to use normal Javascript objects (like most things in Node-Red).

I have support to accept JSON strings but this gets crazy and is limited. I had some external application that created and injected the JSON strings into the MQTT topics and was causing me a lot of issues.

BTW, I think I have most of the FIXME stuff fixed. I will have to double check it as I haven't looked at the code properly in a while.

Note: This node grew out of Peter Scargill's timer and it still supports the type's of inputs he has. I'll need to promote the Javascript object and demote Pete's inputs. Hopefully that will reduce the confusion.

I would generally recommend not trying to interpret JSON string inputs, as you found it is not that easy. As anyone who does have JSON can easily convert it using the JSON node there is not much reason to support it in indivual nodes.
Which node of Pete's are your referring to? contrib-bigtimer doesn't support JSON strings does it?