Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AND OR in IF conditions? #788

Closed
ilengyel opened this issue Apr 14, 2023 · 3 comments
Closed

AND OR in IF conditions? #788

ilengyel opened this issue Apr 14, 2023 · 3 comments
Labels
question Further information is requested

Comments

@ilengyel
Copy link
Contributor

Is it possible to have AND OR elements in if conditions? I am trying to write a timer script for some lights:

startDriver ntp
ntp_timeZoneOfs 10:00

alias low_lights backlog led_temperature 500; led_dimmer 5; led_enableAll 1; echo lights_low
alias high_lights backlog led_temperature 300; led_dimmer 30; led_enableAll 1; echo lights_high
alias off_lights backlog led_enableAll 0; echo lights_off

addClockEvent 19:00 0xff 1 high_lights
addClockEvent 21:00 0xff 1 low_lights
addClockEvent 23:00 0xff 1 off_lights

delay_s 10

if $hour>=21AND$hour<23 then low_lights
if $hour>=19AND$hour<21 then high_lights
if $hour>=23 then off_lights
if $hour<19 then off_lights

I am not seeing any errors in the logs with the above script, but it appears that the conditions $hour>=21AND$hour<23 and $hour>=19AND$hour<21 evaluate to true.

@ilengyel ilengyel changed the title AND OR for IF conditions? AND OR in IF conditions? Apr 14, 2023
@openshwprojects
Copy link
Owner

Hello,
I really had to read your script three times to realize, but we obviously use the following syntax:
image
So try && and ||

@openshwprojects openshwprojects added the question Further information is requested label Apr 14, 2023
@ilengyel
Copy link
Contributor Author

Thanks, that worked, here is an update of my working timer script:

startDriver ntp
ntp_timeZoneOfs 10:00

alias high_lights backlog led_temperature 300; led_dimmer 30; led_enableAll 1; echo lights_set_high
alias low_lights backlog led_temperature 500; led_dimmer 5; led_enableAll 1; echo lights_set_low
alias off_lights backlog led_enableAll 0; echo lights_set_off

// Events to turn on, dim and turn off
addClockEvent 18:02 0xff 1 high_lights
addClockEvent 21:00 0xff 1 low_lights
addClockEvent 23:00 0xff 1 off_lights

delay_s 8

// Determine initial state based on time of day
if $hour>=18&&$hour<21 then high_lights
if $hour>=21&&$hour<23 then low_lights
if $hour>=23||$hour<18 then off_lights

@openshwprojects
Copy link
Owner

Can I put that in autoexec examples? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants