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
3 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: