Astro Binding: Sunrise next day

Continuing the discussion from

I use OH3-UI configuration for that - I can’t add a channel for Astro-Binding. Is there a way I can utilize this undocumented channel nevertheless? or does anyone with knowledge try and add those channels (could be using the “show advanced” feature) to the official binding rollout?

UseCase:
know, when the sunrise is next day, so I can use this for calculations

  1. for heating purposes
  2. for some light’s logic
  3. for solar excess calculation

thanks!

Have a look into the thing actions.
You could create a rule that will get the information you want via the thing action.
An example is included in the official documentation

1 Like

I tried the example from the docs (with JS Scripting):

var sunActions = actions.Things.getActions("astro","astro:sun:local")
if(null === sunActions) {
  console.log("actions: sunActions not found, check thing ID");
} else {
  var sunEvent = "SUN_SET"
  var today = time.ZonedDateTime.now();
  var sunEventTime = sunActions.getEventTime(sunEvent,today,"START");
  console.log("AstroActions: "+sunEvent+" will happen at ", sunEventTime.toString());
}

and it works with “today”:

2022-11-02 11:33:57.839 [INFO ] [omation.script.ui.EMS_CalcDunkelzeit] - AstroActions: SUN_SET will happen at  2022-11-02T16:54+01:00

so, where can I change that to “tomorrow”?

  var sunEventTime = sunActions.getEventTime(sunEvent,tomorrow,"START");
has errors:
2022-11-02 11:35:03.835 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: ReferenceError: "tomorrow" is not defined

and

  var sunEventTime = sunActions.getEventTime(sunTomorrow,today,"START");
has errors:
2022-11-02 11:36:09.891 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: ReferenceError: "sunTomorrow" is not defined

what syntax do I need to use?

The “today” in

sunActions.getEventTime(sunEvent,today,"START");

is only the variable defined one line above.
You need to create a different zoned datetime variable

Also if you want to change the event in the sample code, it’s defined in the variable and you need to change the variable value instead of the name

2 Likes

oh. yeah. sorry - of course today references a variable - not some attribut-value.
I somehow thought from the “sunTomorrow”-code entry, that I’ll somehow had to do something with that. but makes perfectly sense to use a DateTime variable for “tomorrow” → and it works:

for those struggling with it also, here’s the complete code JS Scripting style:

var sunActions = actions.Things.getActions("astro","astro:sun:local")
if(null === sunActions) {
  console.log("actions: sunActions not found, check thing ID");
} else {
  var sunEvent = "SUN_RISE"
  var today = time.ZonedDateTime.now();
  var sunEventTime = sunActions.getEventTime(sunEvent,today.plusDays(1),"START");
  console.log("AstroActions: "+sunEvent+" will happen at ", sunEventTime.toString());
}
2022-11-02 11:46:27.800 [INFO ] [omation.script.ui.EMS_CalcDunkelzeit] - AstroActions: SUN_RISE will happen at  2022-11-03T07:06+01:00

2 Likes