# Cronplus node, location as an environment or context variable

**URL:** <https://discourse.nodered.org/t/cronplus-node-location-as-an-environment-or-context-variable/58687>\
**Category:** General\
**Created:** [20 February 2022 12:40 UTC](https://discourse.nodered.org/t/cronplus-node-location-as-an-environment-or-context-variable/58687 "2022-02-20T12:40:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaddelLinux](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daddellinux/32/56606_2.png) [@DaddelLinux](https://discourse.nodered.org/u/DaddelLinux)\
**Post date:** [20 February 2022 12:40 UTC](https://discourse.nodered.org/t/cronplus-node-location-as-an-environment-or-context-variable/58687/1 "2022-02-20T12:40:06Z")

</div>

Hi there,

I would like to assign an environment or context variable to the location in solar events mode.  
Having had no success with it myself so far, I need your help. Can anyone tell me if that is possible? An example would be nice.

Thanks

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [20 February 2022 13:28 UTC](https://discourse.nodered.org/t/cronplus-node-location-as-an-environment-or-context-variable/58687/2 "2022-02-20T13:28:32Z")

</div>

Hello ..

> [@DaddelLinux](#):
>
> I would like to assign an environment or context variable to the location in solar events mode

this can achieved by sending a command to Cronplus to create a dynamic schedule.  
With the use of a Function node you can pick up the environment variables (with the location information) and construct the `add` command for the cronplus schedule.

**Based on the example in the cronplus Help tab :**

```auto
let longitude = env.get("longitude") // or flow.get("longitude")
let latitude = env.get("latitude")

msg.payload = {
  "command": "add",
  "name": "alarm1",
  "expressionType": "solar",
  "solarType": "selected",
  "solarEvents": "civilDawn,sunrise,sunset",
  "location": `${longitude} ${latitude}`,
  "offset": "-60",
  "payloadType": "str",
  "payload": "In 60 mins, it will be a great time to take photographs",
  "limit": null
}

return msg;

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/2/123ca9b6582e0c374f57b316ed65afc23dc03263.png)

**Example Flow**

```auto
[{"id":"a19651639c4f34d0","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":1200,"wires":[["4b72bfadd34ef45e"]]},{"id":"4b72bfadd34ef45e","type":"function","z":"54efb553244c241f","name":"add dynamic schedule","func":"let longitude = env.get(\"longitude\")\nlet latitude = env.get(\"latitude\")\n\n\nmsg.payload = {\n \"command\": \"add\",\n \"name\": \"alarm1\",\n \"expressionType\": \"solar\",\n \"solarType\": \"selected\",\n \"solarEvents\": \"civilDawn,sunrise,sunset\",\n \"location\": `${longitude} ${latitude}`,\n \"offset\": \"-60\",\n \"payloadType\": \"str\",\n \"payload\": \"In 60 mins, it will be a great time to take photographs\",\n \"limit\": null\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":1200,"wires":[["4a59d86d8f101651","b6a7d932dd04df8f"]]},{"id":"fded7029d539533e","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":870,"y":1200,"wires":[]},{"id":"4a59d86d8f101651","type":"cronplus","z":"54efb553244c241f","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[],"x":640,"y":1200,"wires":[["fded7029d539533e"]]},{"id":"b6a7d932dd04df8f","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":1100,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![DaddelLinux](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daddellinux/32/56606_2.png) [@DaddelLinux](https://discourse.nodered.org/u/DaddelLinux)\
**Post date:** [20 February 2022 13:33 UTC](https://discourse.nodered.org/t/cronplus-node-location-as-an-environment-or-context-variable/58687/3 "2022-02-20T13:33:52Z")

</div>

Hi there,  
Great! That's exactly what I was looking for.  
Thanks very much

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 March 2022 13:34 UTC](https://discourse.nodered.org/t/cronplus-node-location-as-an-environment-or-context-variable/58687/4 "2022-03-06T13:34:49Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
