Conditional Switch Turn on - OH3

@ubeaut Thanks! maybe coding a timer into the rule or a script would avoid the need to have the virtual item? - i ask because i was to also do something similar with the electric hot water heater - although expiry would be smarter here indeed.

Yes you can put a timer in the rule if you wanted to but if you are not a coder and just want to pint and click rules then you can do it with virtual switch or the physical switch.

Choice is yours to make…You don’t have to do it a certain way of you don’t want to.

I use expire the most and only have one timer in a rule. Both ways work well.

1 Like

You would put the timer command in the rule just after it sends the command to turn the light on.

I don’t know if the timer or the GUI based expire is better, someone with knowledge of Openhab internals would need to speak to that. I just prefer rules files vs the GUI.

1 Like

I’ve found virtual item very convenient for light switching based on motion sensors. When motion sensor detects a motion in controlled room, a rule is checking if it`s not daytime and main room light is not on already with rule condition. Then rule refreshes lightlevel sensor to check if there is some other light source so main light is not needed. After that rule triggers on main light and a proxy timer item with expire metadata set to 2 minutes.

  var light = WallmountFamilyRoom_Lightlevel.state as Number
if(light < 1) {

Every motion event after that checks if timer item is still on, and sends

postUpdate(FamilyRoomLightTimer, ON)

to reset expire timer and to restart 2 minutes countdown.
And a very simple UI rule turns off main light when timer item expires.
This is working like a charm for kitchen and other zones where you do move all the time you spend there - we are not using conditional switches or voice commands anymore.

1 Like

I have Phillips Hue sensors for light readings:

The rule is if motion is detected and the lux is less than 4 and the Lamp in the lounge room is off then turn on the small lamp which has the expire set on it.

I have the check fro the lounge light is off because it is dimmable and can get below 4 lux.

1 Like

I should mention that I tried expire for my hotwater heater, wanted an auto-off after 35mins but it seems expire is limited to small time amounts - i read that it resets the expire timer after any device update so 2 mins is prob ok but 35 gets reset time and time again probably due to traffic updates.

so timer in a script is more applicable i think!

(more info from here - Expire timer does not always work)

Just use a proxy item for expire timer if somehow you update your main item during expire countdown. And a simple rule - when timer item switches off - switch off main item. And btw, i have 2 hours expire timer on watering valve working every day without issues, so expire timer itself is not an issue.

can you show me how you set it without a proxy item pls? maybe i did something wrong

Just a switch item, not linked to any thing/channel, with expire metadata on him.

what action do you choose to use? update state or send command?

send command OFF

1 Like

Quick question, does the sunphasename variable relate to a channel you have linked? i.e. do you create a channel (which one) to be able to rever to daylight?

I use a variable just for quick transform from “234 lumens” to “234” so i could compare this variable with needed number. And daylight check is made in UI rule condition - there is no need of variable, i just check that TimeOfDay item != DAY. This item is made with the use of Rich Koshak’s design pattern TimeOfDay

Look at his:

It uses virtual switch because the real item gets updated and resets the timer.

@ubeaut what about your setup? i still find that calling the dusk dawn channels from astro works best as triggers for my virtual switch which defines night and day but I understand that there maybe a channel that does this anyway and i could use that as a trigger?

I don’t use a virtual switch to see if it is night or day.
I use the Astro sun phase name. You can see if it is night or daylight from that.

Basically I use if the phase name is not equal to daylight then it is getting dark or it’s dark which covers what I want to do.

1 Like

@ubeaut i got that - sorry it is the last channel in the list :slight_smile:

I’ve read several threads where you’ve mentioned using the sun phase name channel.
Question: what version of openHAB are you using?

I’ve set up a test system (Pi4) with latest stable openHABian, astro binding is the only binding installed and sun phase name is constantly returning UNDEF
A restart of openHAB causes it to report the correct sun phase name for a brief time but it quickly returns to UNDEF
I’ve checked the state using REST, rules logging out state and value in UI all return UNDEF


I am currently not at home to give you a complete answer but I am using openhab 3 latest stable version. I am running on Ubuntu 20.04.
It is not openhabian.
The only thing it sounds like to me is the latitude and longitude may not be correct and the astro binding cannot calculate anything.

Also check the date and time as you don’t have a real time clock in the pi.

1 Like

Nailed it Greg!
openHABian comes with timezone Berlin :rofl:

steps to fix for the interested

openhabian@openhabian:~ $ timedatectl
               Local time: Sat 2021-10-23 00:36:18 CEST
           Universal time: Fri 2021-10-22 22:36:18 UTC
                 RTC time: n/a
                Time zone: Europe/Berlin (CEST, +0200)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
openhabian@openhabian:~ $ timedatectl list-timezones | grep America/New
openhabian@openhabian:~ $ timedatectl set-timezone 'America/New_York'
==== AUTHENTICATING FOR org.freedesktop.timedate1.set-timezone ===
Authentication is required to set the system timezone.
Authenticating as: ,,, (openhabian)
openhabian@openhabian:~ $ timedatectl
               Local time: Fri 2021-10-22 18:38:51 EDT
           Universal time: Fri 2021-10-22 22:38:51 UTC
                 RTC time: n/a
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
openhabian@openhabian:~ $ systemctl restart openhab
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'openhab.service'.
Authenticating as: ,,, (openhabian)

I live east coast USA