How to write OLED status to variable

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
marstu
Normal user
Posts: 22
Joined: 29 May 2021, 02:15

How to write OLED status to variable

#1 Post by marstu » 08 Jun 2021, 21:30

Hi all,

I am using the following rule to switch my OLED on and off:

Code: Select all

on Clock#Time=All,20:00 do //will run once a day
 oledframedcmd,display,off
endon

on Clock#Time=All,06:30 do //will run once a day
 oledframedcmd,display,on
endon
Which is working perfectly, now I would like to write the status of the display to a dummy device. Due to my age I am to lazy to walk in to the living room to find out if the display is off :D I thought the following would help, but didn't:

Code: Select all

on Display_XYZ#state=off do
 taskvalueset,6,1,1
endon
or

Code: Select all

on displayoff do
 taskvalueset,6,1,1
endon
Any idea how to solve?

Thanks and greetings
marstu

User avatar
Ath
Normal user
Posts: 885
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to write OLED status to variable

#2 Post by Ath » 08 Jun 2021, 22:06

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.
/Ton

User avatar
Ath
Normal user
Posts: 885
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to write OLED status to variable

#3 Post by Ath » 08 Jun 2021, 22:16

This solution is not keeping a state (yet), but I'll update that post later to add that if needed, as currently the display is always turned off after 1 minute, so no need to worry if it is turned off in time.
/Ton

marstu
Normal user
Posts: 22
Joined: 29 May 2021, 02:15

Re: How to write OLED status to variable

#4 Post by marstu » 08 Jun 2021, 23:07

Ath wrote: 08 Jun 2021, 22:06 There are 2 challenges with this:
- You can't read the state of the display
What a pity.
- 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
I know, that's the reason why all are already only switched on for a few hours
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
Would be great, when there is one.
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 ;)
I already ordered some PIRs, either my problems will be solved here in the forum or I have to buy some new toys :D Great!
If you don't want to activate the display during the night-hours, all these actions can only be controlled from rules.
This would be ok.
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.
I decided to go with this option, great idea, I will book some hours at the weekend to setup this new toy. Thanks a lot for this great idea.

marstu
Normal user
Posts: 22
Joined: 29 May 2021, 02:15

Re: How to write OLED status to variable

#5 Post by marstu » 08 Jun 2021, 23:08

Ath wrote: 08 Jun 2021, 22:16 This solution is not keeping a state (yet), but I'll update that post later to add that if needed, as currently the display is always turned off after 1 minute, so no need to worry if it is turned off in time.
I'll let you know next week, but I guess this should solve my "problem".

marstu
Normal user
Posts: 22
Joined: 29 May 2021, 02:15

Re: How to write OLED status to variable

#6 Post by marstu » 10 Jun 2021, 22:17

Hi Ath,

I slightly adapted your code and it seems to work, but need some further testing.
Ath wrote: 08 Jun 2021, 22:06

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.
With yours and one of my other roles, the ESP seems to restart every 3 to 4 min. After deleting this rule:

Code: Select all

on System#Boot do
  timerSet,1,60  // Set timer 1
endon

on WiFi#Disconnected do
  timerSet,1,60  // Set timer 1
endon

on WiFi#Connected do
  timerSet,1,0  // Clear timer 1
endon

On Rules#Timer=1 do
  Reboot
endOn
The ESP is at least now up for 112 min

This is my slightly changed one:

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
  else
    OledFramedCmd,display,off
  endif
endon

on rules#timer=1 do
  AsyncEvent,displayoff // Timer turns display off
endon

on displayoff do
  OledFramedCmd,display,off
endon
My PIR is currently a way to sensitive and some adjustments are required, but this will be done at the weekend.

KR marstu

User avatar
Ath
Normal user
Posts: 885
Joined: 10 Jun 2018, 12:06
Location: NL

Re: How to write OLED status to variable

#7 Post by Ath » 10 Jun 2021, 22:26

I don't know why you would want to reboot if Wifi is away for > 60 seconds? Shouldn't be needed, I think.
If the display timer interferes with your Wifi check timer, then one of them should be using another timer, there are 8 available.
Now using timer 2:

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,2,60 // Keep display on for 1 minute, then turn off
  else
    OledFramedCmd,display,off
  endif
endon

on rules#timer=2 do
  AsyncEvent,displayoff // Timer turns display off
endon

on displayoff do
  OledFramedCmd,display,off
endon
I have opened a new PR #3684 that adds the option to send events on Display On/Off and change of Contrast. I'm thinking if I should add an event on page-change, but that'll be a bit more complex
/Ton

marstu
Normal user
Posts: 22
Joined: 29 May 2021, 02:15

Re: How to write OLED status to variable

#8 Post by marstu » 10 Jun 2021, 23:39

Ath wrote: 10 Jun 2021, 22:26 I don't know why you would want to reboot if Wifi is away for > 60 seconds? Shouldn't be needed, I think.
Because downstairs I have really a bad WIFI connection with the latest MEGA version, that was the reason for this rule, and it is quite helpful.
Ath wrote: 10 Jun 2021, 22:26 If the display timer interferes with your Wifi check timer, then one of them should be using another timer, there are 8 available.
Now using timer 2:

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,2,60 // Keep display on for 1 minute, then turn off
  else
    OledFramedCmd,display,off
  endif
endon

on rules#timer=2 do
  AsyncEvent,displayoff // Timer turns display off
endon

on displayoff do
  OledFramedCmd,display,off
endon
I have opened a new PR #3684 that adds the option to send events on Display On/Off and change of Contrast. I'm thinking if I should add an event on page-change, but that'll be a bit more complex
Ah, again I learnt something new, thanks. Will try tomorrow, or at the weekend, and let you know.

TD-er
Core team member
Posts: 4868
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: How to write OLED status to variable

#9 Post by TD-er » 10 Jun 2021, 23:46

If the WiFi reception is worse, please increase TX pwr to 20.5 dBm and check sending with highest TX power.
Setting to B/G mode will allow you to actually send with more TX power compared to "n" network. (20.5 dBm can only be achieved with 'b', which we don't use, so max. is 17 dBm)

marstu
Normal user
Posts: 22
Joined: 29 May 2021, 02:15

Re: How to write OLED status to variable

#10 Post by marstu » 11 Jun 2021, 00:30

TD-er wrote: 10 Jun 2021, 23:46 If the WiFi reception is worse, please increase TX pwr to 20.5 dBm and check sending with highest TX power.
I already ticked sending with highest TX power, but will also change to 20.5 dBm.
TD-er wrote: 10 Jun 2021, 23:46 Setting to B/G mode will allow you to actually send with more TX power compared to "n" network. (20.5 dBm can only be achieved with 'b', which we don't use, so max. is 17 dBm)
Ok, will try B/G mode as well.

marstu
Normal user
Posts: 22
Joined: 29 May 2021, 02:15

Re: How to write OLED status to variable

#11 Post by marstu » 11 Jun 2021, 15:51

marstu wrote: 10 Jun 2021, 23:39
Ath wrote: 10 Jun 2021, 22:26 If the display timer interferes with your Wifi check timer, then one of them should be using another timer, there are 8 available.
Now using timer 2:

I have opened a new PR #3684 that adds the option to send events on Display On/Off and change of Contrast. I'm thinking if I should add an event on page-change, but that'll be a bit more complex
Ah, again I learnt something new, thanks. Will try tomorrow, or at the weekend, and let you know.
With the change in timer it looks like that everything re the PIR is working as it should. The display switches on, when the PIR detects something and went of after 1 minute. Furthermore, there are no reboots any more. So, thanks for your help.

marstu
Normal user
Posts: 22
Joined: 29 May 2021, 02:15

Re: How to write OLED status to variable

#12 Post by marstu » 11 Jun 2021, 15:52

marstu wrote: 11 Jun 2021, 00:30
I already ticked sending with highest TX power, but will also change to 20.5 dBm.

Ok, will try B/G mode as well.
With these changes WIFI seems to be a little more stable, slower, but stable.

Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests