Astro Events

logo

This library adds blocks to determine whether a given phase in today’s astro events have already passed, and retrieve time intervals between the current time and the time of the event. You need the Astro binding installed, and a Sun thing configured.

Blocks

image

This block will return whether or not the specified phase (start or end), like sunrise or sunset, is still to come or has already passed. Don’t forget to pick the Sun thing from the Astro binding!

image

This block will return the number of seconds, minutes or hours (rounded) until the specified phase (start or end), like sunrise or sunset. If it has already passed, the result will be negative. Don’t forget to pick the Sun thing from the Astro binding!

Changelog

Version 0.1

  • initial release

Resources

uid: astro
tags: []
props:
  parameters: []
  parameterGroups: []
component: BlockLibrary
config:
  name: Astro
slots:
  blocks:
    - component: BlockType
      config:
        type: compare_event_time
        message0: the %1 of today's %2 according to %3 %4
        args0:
          - type: field_dropdown
            name: MOMENT
            options:
              - - start
                - START
              - - end
                - END
          - type: field_dropdown
            name: PHASE
            options:
              - - sunrise
                - SUN_RISE
              - - sunset
                - SUN_SET
              - - astro dawn
                - ASTRO_DAWN
              - - nautic dawn
                - NAUTIC_DAWN
              - - civil dawn
                - CIVIL_DAWN
              - - astro dusk
                - ASTRO_DUSK
              - - nautic dusk
                - NAUTIC_DUSK
              - - civil dusk
                - CIVIL_DUSK
              - - daylight
                - DAYLIGHT
              - - noon
                - NOON
              - - night
                - NIGHT
              - - morning night
                - MORNING_NIGHT
              - - evening night
                - EVENING_NIGHT
          - type: input_value
            name: THING
          - type: field_dropdown
            name: DIRECTION
            options:
              - - is still to come
                - After
              - - has already passed
                - Before
        output: Boolean
        colour: 0
        tooltip: ""
        helpUrl: ""
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: "{{utility:things}}.getActions('astro', {{input:THING}}).getEventTime('{{field:PHASE}}', null, '{{field:MOMENT}}').is{{field:DIRECTION}}({{utility:zdt}}.now())"
        toolbox:
          - component: PresetInput
            config:
              name: THING
              type: oh_thing
              shadow: true
    - component: BlockType
      config:
        type: time_until_event
        message0: number of %1 until the %2 of today's %3 according to %4
        args0:
          - type: field_dropdown
            name: UNIT
            options:
              - - seconds
                - SECONDS
              - - minutes
                - MINUTES
              - - hours
                - HOURS
          - type: field_dropdown
            name: MOMENT
            options:
              - - start
                - START
              - - end
                - END
          - type: field_dropdown
            name: PHASE
            options:
              - - sunrise
                - SUN_RISE
              - - sunset
                - SUN_SET
              - - astro dawn
                - ASTRO_DAWN
              - - nautic dawn
                - NAUTIC_DAWN
              - - civil dawn
                - CIVIL_DAWN
              - - astro dusk
                - ASTRO_DUSK
              - - nautic dusk
                - NAUTIC_DUSK
              - - civil dusk
                - CIVIL_DUSK
              - - daylight
                - DAYLIGHT
              - - noon
                - NOON
              - - night
                - NIGHT
              - - morning night
                - MORNING_NIGHT
              - - evening night
                - EVENING_NIGHT
          - type: input_value
            name: THING
        output: Boolean
        colour: 0
        tooltip: Determines the amount of time until the specified event. If it has already passed, the result will be negative.
        helpUrl: ""
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: "{{utility:zdt}}.now().until({{utility:things}}.getActions('astro', {{input:THING}}).getEventTime('{{field:PHASE}}', null, '{{field:MOMENT}}'), {{utility:ChronoUnit}}.{{field:UNIT}})"
        toolbox:
          - component: PresetInput
            config:
              name: THING
              type: oh_thing
              shadow: true
  utilities:
    - component: UtilityJavaType
      config:
        name: things
        javaClass: org.openhab.core.model.script.actions.Things
    - component: UtilityJavaType
      config:
        name: zdt
        javaClass: java.time.ZonedDateTime
    - component: UtilityJavaType
      config:
        name: ChronoUnit
        javaClass: java.time.temporal.ChronoUnit
4 Likes

When I try to add this to my OH3.2 instance I find the following error in the log:

[ERROR] [ity.CommunityBlockLibaryAddonHandler] - Unable to parse YAML: Cannot deserialize value of type `java.util.Date` from String "Dec 12, 2021, 7:09:58 PM": not a valid representation (error: Failed to parse Date value 'Dec 12, 2021, 7:09:58 PM': Unparseable date: "Dec 12, 2021, 7:09:58 PM")

I removed the timestamp, please try again!

Working fine now. Thanks a lot :slight_smile:

Hi has anyone this working on new openhab 4 with the new script type “ECMAScript (ECMAScript 262 Edition 11)”?
I only get it to work with the old “ECMAScript (ECMA - 262 Edition 5.1)” openhab 3 Script Type.

It is working for me, in ECMA - 262 Edition 5.1 and in ECMAScript 262 Edition 11

thanks for your replay.
OK i will test it from scratch and creat the rules new.
On other rules i only hat to save it in blocky editor again and they worked but thes rules with the astro blocks dose not worke.
Here an example:

Try the Block like tis

it also works without the “copy of” block

See also here

You can not compare the Astro blocks from this library with a time like you did in the blocks you shown,
one of the blocks only return true or false, the other a number of sconds, minutes or hours.

Ah Ok,
thanks for you tipp i will try with “copy of” block.

But the funny thing is the shown block is working for me on Openhab 4 with “ECMA - 262 Edition 5.1”.