There are 2 challenges with this:
- You can't read the state of the display
- The OLED should not be kept on for prolonged times, as its content will burn in, most likely within a few months, depending on the brightness level
Well, now let's try and find solutions for that.
What needs to be done:
- Keep the current state
- Turn the display off between 20:00 in the evening and 06:30 in the morning
- Turn off the display after it was turned on
Looking at those requirements, I'd say that the 'keep off during the night' task can be skipped if the display is turned off after being on for some time. But that's just my opinion
There are multiple ways to turn on the display, simplest is to use the Display button option, and set a reasonable time after which it is turned off again
For that button to activate, there can be an actual button to be pressed, or, more conveniently, a Pir sensor that is triggered when someone approaches the unit. Not even any rules needed here.
If you don't want to activate the display during the night-hours, all these actions can only be controlled from rules.
Keeping the state can be done in internal variables, to be set using the LET command, or in a Dummy device, that can hold up to 4 (numeric) values, using the TASKVALUESET command.
Using the most complex options, off during the night, Pir sensor turns it on, I'd go for these rules:
Code: Select all
on PIR#State=1 do // Most PIR sensor give a high signal when activated
AsyncEvent,displayon
endon
on displayon do
if %systm_hm% < 20:00 and %systm_hm% > 06:30 // Only when we are awake
OledFramedCmd,display,on
TimerSet,1,60 // Keep display on for 1 minute, then turn off
endif
endon
on displayoff do
OledFramedCmd,display,off
endon
on rules#timer=1 do
AsyncEvent,displayoff // Timer turns display off
endon
Disclaimer: Untested code.