[SOLVED] Rule with more then one condition

Hello

I have door sensor and light switch
When the door is opened AND eveningNight event from astro binding is on start I wont to turn on the light for 30 second
My rule:

rule "Door open light for 30 sec"
when
    Item ZWaveNode007ZD21025DoorWindowSensor_SensorAlarm received update OPEN
then
    //logInfo("loggerName", Channel "astro:sun:local:eveningNight#event")
   if("astro:sun:local:eveningNight#event" == START){
    ZWaveNode008ZMNHBDFlush2Relays_Switch2.sendCommand (ON)
        createTimer(now.plusSeconds(30), [|
        ZWaveNode008ZMNHBDFlush2Relays_Switch2.sendCommand (OFF)
        ]
        )
    }
end

And the error is:

2019-07-09 22:43:48.154 [INFO ] [se.smarthome.model.script.loggerName] - astro:sun:local:eveningNight#event

2019-07-09 22:43:48.159 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Door open light for 30 sec': The name 'START' cannot be resolved to an item or type; line 20, column 47, length 5

How can I add condition for channel state?

Oded

Make a DateTime item referencing the channel & reference the item. That is the purpose of Items, I believe.
The Thing channels show what is available but they cannot be used unless linked to an Item.

You cannot because what you query is not a channel state. It’s an event, technically speaking that has no state and no duration.

Create another rule that sets a global variable or item (DateTime or Switch type, whatever you feel is easiest to work with) when that event occurs and in your original rule, query that variable/item state.

1 Like

So, does the weather1 binding make items automatically to monitor states or does it do something different?
Just curious,

OH2 bindings make channels available, sometimes automatically from things, sometimes you have to configure them.
It’s up to you to link channels to Items that you choose to create.
These have to be state-type channels.
You cannot link event channels.
You can listen for event channels by rule, and of course a rule can update Items.

No “Name1” binding has this concept. All bindings that end with “1” are 1.x version bindings which do not have a concept of Things, Channels, Links, or events. In the old Astro1 binding, the equivalent of the event Channel was a Switch Item that momentarily gets turned ON then immediately OFF at the instant the event occurs.

The weather1binding doesn’t automatically do anything really, except periodically poll a supported weather service and update Items with the downloaded values.

1 Like

Thanks. Just trying to learn from the “masters” :smiley:

@rossko57 Is it possible to change the item state with one rule?
Can I trigger the rule when the event changed and read the changed event or I need to create 2 rule one for each state?

I’m guessing the question is really about this

Rules don’t cost you anything. Don’t be afraid of having many small rules doing simple tasks.

item

Switch EveningSwitch "Evening-night condition [%s]"
rule "Evening switch"
  when
    Channel 'astro:sun:local:eveningNight#event' triggered
  then
    if (receivedEvent.getEvent() == "START") {
        EveningSwitch.postUpdate(ON)
    } else {
        EveningSwitch.postUpdate(OFF)
    }
end

but the getEvent used there has problems in some recent OH versions. With no idea what you’re using, why not just have two rules. Easier to choose different events too.

rule "Evening begins"
  when
    Channel 'astro:sun:local:eveningNight#event' triggered START
  then
        EveningSwitch.postUpdate(ON)
end

rule "Evening ends"
  when
    Channel 'astro:sun:local:eveningNight#event' triggered END
  then
        EveningSwitch.postUpdate(OFF)
end
1 Like