Astro Daylight Switch without rule?

In the process of migrating one of my old textual rules to UI rules, I thought I might have found a way to eliminate two simple rules and have the Astro binding control a switch.

Textual rules:

rule "Sunrise Rule"
when Channel "astro:sun:local:rise#event" triggered START
then DaylightHours.postUpdate("ON")
end 

rule "Sunset Rule"
when Channel "astro:sun:local:set#event" triggered START 
then DaylightHours.postUpdate("OFF")
end 

I was hoping to use the Astro Binding Local Sun Thing channel Daylight / Range event to switch the DaylightHours switch item. I was encouraged when I tried to Link a new item to the channel in the UI and the default Type was switch. But when I try to Link an item (new or existing) to the channel, I get an error “There is no profile available for the selected item.”

Here is what the Link channel to item screen looks like:

There are two profiles listed, but they are not clickable. It seems like what I need is a profile that uses the START and END triggers to turn the switch item ON and OFF.

I feel like I’m missing something, but perhaps it is not intended to work the way that I want it to.

Here is my system information

runtimeInfo:
  version: 3.4.0.M1
  buildString: Milestone Build
locale: en-US
systemInfo:
  configFolder: /etc/openhab
  userdataFolder: /var/lib/openhab
  logFolder: /var/log/openhab
  javaVersion: 11.0.16
  javaVendor: Raspbian
  osName: Linux
  osVersion: 5.15.61-v7l+
  osArchitecture: arm
  availableProcessors: 4
  freeMemory: 643935800
  totalMemory: 1021313024
  startLevel: 70
bindings:
  - amazonechocontrol
  - astro
  - denonmarantz
  - harmonyhub
  - icalendar
  - icloud
  - ipcamera
  - mail
  - mqtt
  - myq
  - network
  - omatic
  - openweathermap
  - remoteopenhab
  - tplinksmarthome
  - tuya
  - zwave
clientInfo:
  device:
    ios: false
    android: false
    androidChrome: false
    desktop: true
    iphone: false
    ipod: false
    ipad: false
    edge: false
    ie: false
    firefox: false
    macos: false
    windows: true
    cordova: false
    phonegap: false
    electron: false
    nwjs: false
    webView: false
    webview: false
    standalone: false
    os: windows
    pixelRatio: 1.5
    prefersColorScheme: light
  isSecureContext: false
  locationbarVisible: true
  menubarVisible: true
  navigator:
    cookieEnabled: true
    deviceMemory: N/A
    hardwareConcurrency: 4
    language: en-US
    languages:
      - en-US
    onLine: true
    platform: Win32
  screen:
    width: 1707
    height: 1067
    colorDepth: 24
  support:
    touch: false
    pointerEvents: true
    observer: true
    passiveListener: true
    gestures: false
    intersectionObserver: true
  themeOptions:
    dark: light
    filled: true
    pageTransitionAnimation: default
    bars: filled
    homeNavbar: default
    homeBackground: default
    expandableCardAnimation: default
  userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,
    like Gecko) Chrome/105.0.0.0 Safari/537.36
timestamp: 2022-09-13T14:03:40.234Z

If this doesn’t work, then I will use a single rule to replace the two textual rules:

configuration: {}
triggers:
  - id: "1"
    configuration:
      thingUID: astro:sun:local
      event: ""
      channelUID: astro:sun:local:daylight#event
    type: core.ChannelEventTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      blockSource: <xml xmlns="https://developers.google.com/blockly/xml"><block
        type="controls_if" id="|V6kOOKLg4h)v9lzNJ]S" x="59" y="85"><mutation
        elseif="1"></mutation><value name="IF0"><block type="logic_compare"
        id="@j3g=;_WNgbjNgGi|.,A"><field name="OP">EQ</field><value
        name="A"><block type="oh_context_info" id="ayDnq:ZdKIn;PBvw+52Z"><field
        name="contextInfo">event</field></block></value><value name="B"><block
        type="text" id="UZ7En/{z(n~^W?l]I0*-"><field
        name="TEXT">START</field></block></value></block></value><statement
        name="DO0"><block type="oh_event" id="fIH3|PKr6tRD{y=]h%$+"><field
        name="eventType">sendCommand</field><value name="value"><shadow
        type="text" id="P[RLAQUf3ZP{9478d,Ua"><field
        name="TEXT">ON</field></shadow></value><value name="itemName"><shadow
        type="oh_item" id="`F5^;:]b0XrtM?%VM-t:"><field
        name="itemName">DaylightHours</field></shadow></value></block></statement><value
        name="IF1"><block type="logic_compare" id="9i*6w-12DQ$FKBd!VC[/"><field
        name="OP">EQ</field><value name="A"><block type="oh_context_info"
        id="`]A;x^{{4tfdro[kX#yB"><field
        name="contextInfo">event</field></block></value><value name="B"><block
        type="text" id="LS+P]:2v7A73;]tuZm*C"><field
        name="TEXT">END</field></block></value></block></value><statement
        name="DO1"><block type="oh_event" id="Ap^slRWs-.Q|FRFN=ir0"><field
        name="eventType">sendCommand</field><value name="value"><shadow
        type="text" id="qbRwEDA:CJEVo^F+h)mp"><field
        name="TEXT">OFF</field></shadow></value><value name="itemName"><shadow
        type="oh_item" id="![qp^+2j|E7Li5cJkM2+"><field
        name="itemName">DaylightHours</field></shadow></value></block></statement></block></xml>
      type: application/javascript
      script: |
        if (event.event == 'START') {
          events.sendCommand('DaylightHours', 'ON');
        } else if (event.event == 'END') {
          events.sendCommand('DaylightHours', 'OFF');
        }
    type: script.ScriptAction

Blockly image:

Thanks in advance for any suggestions and help.

You cannot link an Event Channel to an item. That’s kind of the whole point of them. Event Channels represent ephemeral events with no state. Items represent a state.

Thanks for the reply. I didn’t appreciate the important distinction between trigger channels and other types of channels. Your comment led me to Confusion between channels and channel triggers and its links that underscore the difference between and Event Channel and other channels.

It appears I can get what I was looking for (is it daylight?) by using the Astro bindings Sun Phase Name channel, which includes Daylight as one of the phases:

group phase
channel
name (String), values: SUN_RISE, ASTRO_DAWN, NAUTIC_DAWN, CIVIL_DAWN, CIVIL_DUSK, NAUTIC_DUSK, ASTRO_DUSK, SUN_SET, **DAYLIGHT**, NIGHT
1 Like
configuration: {}
triggers:
  - id: "1"
    configuration:
      thingUID: astro:sun:local
      event: START
      channelUID: astro:sun:local:rise#event
    type: core.ChannelEventTrigger
  - id: "2"
    configuration:
      thingUID: astro:sun:local
      event: START
      channelUID: astro:sun:local:set#event
    type: core.ChannelEventTrigger
conditions: []
actions:
  - inputs: {}
    id: "3"
    configuration:
      blockSource: <xml
        xmlns="https://developers.google.com/blockly/xml"><variables><variable
        id="$EPivy4=mZ_4BLKoVia@">Sonnenaufgang</variable><variable
        id="G08G~YCm(2lSlYtFhvTC">Sonnenuntergang</variable></variables><block
        type="variables_set" id="AyPzU-V|x:H[q7/;lRi9" x="175" y="182"><field
        name="VAR" id="$EPivy4=mZ_4BLKoVia@">Sonnenaufgang</field><value
        name="VALUE"><block type="oh_zdt_fromItem"
        id="{mk^oI^yu?NU$?f!Ng2S"><value name="itemName"><shadow type="oh_item"
        id="w^TIfZCoImeKVjxMr:sV"><field
        name="itemName">SonnenaufgangStart</field></shadow></value></block></value><next><block
        type="variables_set" id="k*afPKFFVPtLI6Z#Bo}p"><field name="VAR"
        id="G08G~YCm(2lSlYtFhvTC">Sonnenuntergang</field><value
        name="VALUE"><block type="oh_zdt_fromItem"
        id="QV/DB4A+z`cby@@}9Tgl"><value name="itemName"><shadow type="oh_item"
        id="=AX5O/%RNKO$`%h=jp;,"><field
        name="itemName">SonnenuntergangStart</field></shadow></value></block></value><next><block
        type="controls_if" id="ZYT10z3,fOA8*a_c@+*I"><mutation
        else="1"></mutation><value name="IF0"><block type="logic_operation"
        id="v8p=,=O%I{(eb4nqW{MV"><field name="OP">AND</field><value
        name="A"><block type="logic_compare" id="_@2l+~Yj4a@0s2zMp]TM"><field
        name="OP">GT</field><value name="A"><block type="oh_zdt_now"
        id="Wa[kys_=:z-$DH]TD0I}"></block></value><value name="B"><block
        type="variables_get" id="]C2OfBs{8y)}K;vU4hkI"><field name="VAR"
        id="$EPivy4=mZ_4BLKoVia@">Sonnenaufgang</field></block></value></block></value><value
        name="B"><block type="logic_compare" id="T=aJ?6h:KbaP}+uP[9%b"><field
        name="OP">LT</field><value name="A"><block type="oh_zdt_now"
        id="A,nRcKfiLhS)d]4Erf%x"></block></value><value name="B"><block
        type="variables_get" id="|,n0y{c3k8o#eKRrxlB{"><field name="VAR"
        id="G08G~YCm(2lSlYtFhvTC">Sonnenuntergang</field></block></value></block></value></block></value><statement
        name="DO0"><block type="oh_event" id="($2_v:#j(jAgeYztff:J"><field
        name="eventType">sendCommand</field><value name="value"><shadow
        type="text" id="!W9Q(p1s=1!:FnKbp1VL"><field
        name="TEXT">ON</field></shadow></value><value name="itemName"><shadow
        type="oh_item" id="be,xYVAtKP1VSu;:U4xb"><field
        name="itemName">DaySwitch</field></shadow></value></block></statement><statement
        name="ELSE"><block type="oh_event" id="QzlTDgWNs-myJL7FM_9v"><field
        name="eventType">sendCommand</field><value name="value"><shadow
        type="text" id="+%/C]]gSN.,P]^+t42sS"><field
        name="TEXT">OFF</field></shadow></value><value name="itemName"><shadow
        type="oh_item" id="j!^~xP#K!pOuTs[WFC$Y"><field
        name="itemName">DaySwitch</field></shadow></value></block></statement></block></next></block></next></block></xml>
      type: application/javascript
      script: >
        var Sonnenaufgang, Sonnenuntergang;


        var dtf = Java.type("java.time.format.DateTimeFormatter");


        var zdt = Java.type("java.time.ZonedDateTime");


        /* Try to detect the format based on its length */

        function getZonedDateTime(datetime) {
          datetime = String(datetime).replace('T', ' ')
          switch (datetime.length) {
            case 10: return zdt.parse(datetime + ' 00:00:00+00:00', dtf.ofPattern('yyyy-MM-dd HH:mm:ssz'));
            case 16: return zdt.parse(datetime + ':00+00:00', dtf.ofPattern('yyyy-MM-dd HH:mm:ssz'));
            case 19: return zdt.parse(datetime + '+00:00', dtf.ofPattern('yyyy-MM-dd HH:mm:ssz'));
            case 25: return zdt.parse(datetime, dtf.ofPattern('yyyy-MM-dd HH:mm:ssz'));
            case 23: return zdt.parse(datetime + ' +00:00', dtf.ofPattern('yyyy-MM-dd HH:mm:ss.SSS z'));
            case 26: return zdt.parse(datetime + ' +00:00', dtf.ofPattern('yyyy-MM-dd HH:mm:ss.SSSSSS z'));
            case 29: return zdt.parse(datetime, dtf.ofPattern('yyyy-MM-dd HH:mm:ss.SSSSz'));
            case 32: return zdt.parse(datetime, dtf.ofPattern('yyyy-MM-dd HH:mm:ss.SSSSSSSz'));
            case 28: return zdt.parse(datetime.slice(0,26) + ':' + datetime.slice(26,28), dtf.ofPattern('yyyy-MM-dd HH:mm:ss.SSSSz'));
            default: return zdt.parse(datetime);
          }
        }


        function createZonedDateTime(year, month, day, hour, minute, second, nano, offsetString, timezoneString) {
          stringToParse = '' + year;
          stringToParse += '-' + ('0' + month).slice(-2);
          stringToParse += '-' + ('0' + day).slice(-2);
          stringToParse += 'T' + ('0' + hour).slice(-2);
          stringToParse += ':' + ('0' + minute).slice(-2);
          stringToParse += ':' + ('0' + second).slice(-2);
          stringToParse += '.' + nano + offsetString + '[' + timezoneString + ']';
          return zdt.parse(stringToParse, dtf.ISO_ZONED_DATE_TIME);
        }



        Sonnenaufgang = (itemRegistry.getItem('SonnenaufgangStart').getState().getZonedDateTime());

        Sonnenuntergang = (itemRegistry.getItem('SonnenuntergangStart').getState().getZonedDateTime());

        if ((zdt.now()) > Sonnenaufgang && (zdt.now()) < Sonnenuntergang) {
          events.sendCommand('DaySwitch', 'ON');
        } else {
          events.sendCommand('DaySwitch', 'OFF');
        }
    type: script.ScriptAction