jensrossbach/node-red-contrib-chronos

how to full msg

kuradi opened this issue · 10 comments

my goal is to pass flow.boo to payload, but i have no success.
i have been tried

{
    "topic": "topic/POWER1",
    "payload": "{flow.boo}"
}

and
{ "topic": "topic/POWER1", "payload": "{{flow.boo}}" }
please advise

Hi, can you please give some more details, especially which node you are talking about?

Have you already read the docs? There you can find a lot of information as well as examples.

i have readed all docs but i cant find info suitable for me, maybe you can point me to right direction :)
scheduler node.
image

Ok, so if I understand you correctly, you want to insert the contents of 'flow.boo' using some kind of templating language? This is not supported by the node, but why don't you just put a change node behind the scheduler node and replace payload by the contents of the flow variable? Or use a template node instead of the change node and pass the template to that node.

i dont want template anything if possible. i have stored ON/OFF commands for each hour and want them pass as payload. i just looked your example at docs https://github.com/jensrossbach/node-red-contrib-chronos/wiki/images/node_scheduler_output_fullmsg_json.png and thougth i can replace hardcoded payload to flow, global etc...
image

But your example of your initial description seems to be Mustache-like templates (using e.g. {{...}}) and this is not supported by the scheduler node. You can only load a complete schedule from a context variable as described here. In this case one of your context variables should look like this:

// boiler_today_14
{
    "trigger":
    {
        "type": "time",
        "value": "14:00",
        "offset": 0,
        "random": false
    },
    "output":
    {
        "type":  "fullMsg",
        "value":
        {
            "topic": "topic/POWER1",
            "payload": "ON"
        }
    }
}

In your node configuraton, you should then have something like this (just one schedule as example; the configured output is ignored / overridden by the context variable):
image

As already indicated earlier, I see additional alternatives:

  1. Use a change node to replace the msg.payload of the scheduler node output with the content of the flow variable:
[{"id":"68f53a5762cecd74","type":"tab","label":"Using change node","disabled":false,"info":"","env":[]},{"id":"ca4a493c254d90a4","type":"chronos-scheduler","z":"68f53a5762cecd74","name":"","config":"9c6224aade162652","schedule":[{"trigger":{"type":"time","value":"14:00","offset":0,"random":false},"output":{"type":"fullMsg","value":"{\"topic\": \"topic/POWER1\", \"payload\": \"\"}"}}],"multiPort":false,"disabled":false,"outputs":1,"x":270,"y":220,"wires":[["c438c5f3a945c98d"]]},{"id":"c438c5f3a945c98d","type":"change","z":"68f53a5762cecd74","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"boiler_today_14","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":220,"wires":[[]]},{"id":"9c6224aade162652","type":"chronos-config","name":"Home","sunPositions":[]}]
  1. Use a template node to replace the placeholder set in scheduler node by the content of the flow variable:
[{"id":"68f53a5762cecd74","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"ca4a493c254d90a4","type":"chronos-scheduler","z":"68f53a5762cecd74","name":"","config":"9c6224aade162652","schedule":[{"trigger":{"type":"time","value":"14:00","offset":0,"random":false},"output":{"type":"fullMsg","value":"{\"topic\":\"topic/POWER1\",\"template\":\"{{flow.boiler_today_14}}\"}"}}],"multiPort":false,"disabled":false,"outputs":1,"x":270,"y":220,"wires":[["e3855f6589b2456c"]]},{"id":"e3855f6589b2456c","type":"template","z":"68f53a5762cecd74","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"","output":"str","x":430,"y":220,"wires":[[]]},{"id":"9c6224aade162652","type":"chronos-config","name":"Home","sunPositions":[]}]

thanx for your input, appreciate it.
tried both suggestions. i really dont get how should i use change node if stored value and variable changing every hour :( in template node... i have now correct payload, but this solution is not passing topic to mqtt... pls advise.
edit: template still working. so all good for now. but i would love to see in the future possibility to use stored values as i explained.

Yes, you are right. The template node unfortunately does not passthrough the msg.topic.

Could you maybe provide me a basic flow of what you want to achieve because it is not 100% clear to me how to evaluate the flow variable to be used.

but i got it working, i had just some typo... its working :)
image

trying to explain. we have electricity price which is changing every hour, depending price is low or high system calculates best hours to use for heat etc, i'm storing those values as on/off for every hour. 15.00 "ON", 16.00 "OFF" etc etc....

Great that it's working now. So what is your conclusion? Do you see this topic solved? If yes, could you please close the issue?

One hint for the future: topics like this here should better be placed into the discussion forum. Issues should only be used for bugs and feature requests.

@kuradi Please have a look at release 1.16.0 which I published today. Now you can specify the output using a JSONata expression which in fact allows you to include content from context variables.

For instance, taking your example from the beginning of this discussion, you can write something like this:

{
    "topic": "topic/POWER1",
    "payload": $flowContext("boo")
}