Rules Sunset/Sunrise

hallo everybody,

i am new in Openhab und want to try creating a Rule DSL that make the button of wenn the Sunrise and Sunset betwenn appointed Time, i know that the Sunset and Sunrise linked by Astrobindung, but how can i create the button and then the Rule for ON /OFF??

thanks alot

Can you describe a very clear example of what you want to do?

First a warm welcome to you :wink:

Of course a little more info on what you want to do is helpful. I’m assuming you have lights with switch items that you want to turn on/of when the sun goes down/ comes up. I have something like this, Just create a rule using the civil dusk (or dawn) event that the binding provides. Using an action script with code “events.sendCommand(itemname,ON)” you can turn a switch on.

To provide a full example here a copy of my rule. I’m lazy, so when the sun goes down my rule turns on all lights (switches) that I tagged with “schemer”. Saves coding and easier.

configuration: {}
  - id: "1"
      thingUID: astro:sun:Sun
      event: START
      channelUID: astro:sun:Sun:civilDusk#event
    type: core.ChannelEventTrigger
conditions: []
  - inputs: {}
    id: "6"
      type: application/javascript
      script: >
        var logger =
        Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' +
"Rule schemer running");

        //get items with Tag Schemer

        var items=itemRegistry.getItemsByTag('Schemer');

        //send command ON to all of them (so must be switches)

        for (var item in items){
    type: script.ScriptAction
1 Like

thanks for Your Answer. i will try your Example.

is your Code be wrtitten in RULE DSL or in ESMA Rule ?

The action code itself is in ECMA script. The whole posted code is the for the entire rule. For most thing in openHAB there’s a tab for configuring with the GUI and a second tab with the corresponding code. I took this example by coping that code. Saves a lot of screenshots;-) And can be copied in the code tab of a new empty rule

Of course if you’re not comfortable with coding you can make rules also completely with the GUI by selecting An if from an event in the binding (the dusk/dawn event) and then an action on an item (the switch). You can add multiple Actions, one for each switch.

Or something in between. You can also make ECMA scripts using blockly. This is kind of a Lego thing, creating code by using configurable templates.

Maybe to start this is a nice tutorial for creating a rule with the GUI.

ok, thanks alot for your helpful Answer, i will check it.