Rotary Encoder set values

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Swagner
New user
Posts: 5
Joined: 14 May 2020, 17:45

Rotary Encoder set values

#1 Post by Swagner » 14 May 2020, 18:01

Hello All,

I have the following situaton and would like to know how to set the value for the Rotary Encoder in the Rules.

The Rotary Encoder is used to set three different Relais depending on the values, this works already.
When I push the switch all relais will be turned off and now the rotary switch need to set to 0, this doesn't work.
MQTT should be used to set the Rotary Encoder value to turn on/off the Relais via MQTT Broker or I turn on/off the relais and the Rotary Encoder Value will be set.

When I would uses TaskValueSet and a dummy device for this how I can ensure the Rotary Switch will not reach the max or min limit and would stop working ?

Thanks and cheers,

Stefan

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Rotary Encoder set values

#2 Post by grovkillen » 14 May 2020, 18:09

You can have events that checks if it's above or below your preferred values. It it is, just set it to max/min accordingly.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Swagner
New user
Posts: 5
Joined: 14 May 2020, 17:45

Re: Rotary Encoder set values

#3 Post by Swagner » 14 May 2020, 19:40

Hi Grovkillen,

I guess it's easier with an example:

The Rotary Encoder has min. 0 and max. 3 set (it doesn't matter when a higher number is used it will possible just delay the problem)

a.) Rotary Encoder Switch ON
- When the Rotary Encoder is 1 Relais 1 is on
- When the Rotary Encoder is 2 Relais 2 is on
- When the Rotary Encoder is 3 Relais 3 is on

b.) Rotary Encoder Switch OFF will set Relais 1,2,3 to OFF

When b.) is done the the Rotary Encoder Value is not changed I have to build this by using a Dummy device and EventSetValue (I guess this should work) BUT:
When the Dummy device Value = 0 and all Relais are OFF the Rotary Encoder Value will be still 3 --> The Rotary Encoder has the max value reached and there is no Trigger which can increase the Dummy device Value when I move the rotary encoder to the right or is the a way how to solve this ?

PS: Similar situation can happen when MQTT is used to change the Dummy device value or turn ON/OFF the Ralais 1-3, I didn't found information how to set the Rotary Encoder Value to 0 or any other Value.

Thanks and cheers,

Stefan

Swagner
New user
Posts: 5
Joined: 14 May 2020, 17:45

Re: Rotary Encoder set values

#4 Post by Swagner » 17 May 2020, 18:17

Hi All,

I did several tests and I am not sure if this is a bug or normal, can somebody confirm this ?

I have created the following Rule#

on Rotary#Counter do
TaskValueSet 1,1,[Rotary#Counter]
Publish %sysname%/Counter/Set,[Rotary#Counter]
endon

on Relais#State do
TaskValueSet 2,1,[Relais#State]
Publish %sysname%/Relais/Set,[Relais#State]
endon

on Relais#State=0 do
TaskValueSet 1,1,[Rotary#Counter]=0
Publish %sysname%/Counter/Set,0
endon


When the Relais = 1 and the Rotary to 5
1_5.JPG
1_5.JPG (44.49 KiB) Viewed 17671 times

When the Relais = 0 the Rotary will be set to 0
0_0.JPG
0_0.JPG (42.47 KiB) Viewed 17671 times

Now the Relais = 1 and the Rotary is still set to 0
0_1.JPG
0_1.JPG (45.16 KiB) Viewed 17671 times

Now the Problem when I move the Rotary Encoder it doesn't start with "0" it will start with the last number which was used before it was set to "0" so in this case it will start with a unvisible 5 and change it to 4 or 6
6_1.JPG
6_1.JPG (42.99 KiB) Viewed 17671 times

Cheers,

Stefan

Swagner
New user
Posts: 5
Joined: 14 May 2020, 17:45

Re: Rotary Encoder set values

#5 Post by Swagner » 19 May 2020, 22:10

Hi All,

I did now several hours of tests and it's impossible to overwrite the Rotary Encoder Value by using TaskValueSet.
When TaskValueSet is used the Rotary Encoder Value will change but this is not persistent and the Rotary Encoder will always start with the previous used Rotary Encoder Value.

For all who searched already, there is no command which can be used in the Rules to set the Rotary Encoder to a Start Value or set it to "0"
I have tested with Release mega-20200515

When both GPIO Ports are set to 0 the Rotary Encoder Value can't be changed anymore when the Rotary Encoder is manually moved to left or right.
When both GPIO Ports are set to 1 the Rotary Encoder Value can be again changed when the Rotary Encoder is manually moved to left or right, it will not start from 0 or a set Value.
A combination of "0" and "1" can be used on the GPIO Ports to count +1 or -1 for the Rotary Encoder Value

Possible the only way is to use MQTT but I didn't tested it and I also expect it will not work and the Rotary Encoder will still start from the previous used value.

Hope this save others some time,

Cheers,

Stefan

PS: Thanks to all who are working on the ESP Mega Developement, I always wondering how much can be already done with the ESP

Swagner
New user
Posts: 5
Joined: 14 May 2020, 17:45

Re: Rotary Encoder set values

#6 Post by Swagner » 13 Jun 2020, 10:41

Hi All,

I've done some additional tests and used mega-20200608, upfront nothing has changed.

I did the same tests like before and nothing has been changed.
I tried also http://192.168.1.163/?cmd=taskvalueset,1,1,0 and when the command is executed the value is set to 0 and when the rotray is moved it start from the number which was used before.
As I understood it will be the same when MQTT is used because it use the cmd to set the value.

Summary:
Taskvalueset will not work for the Rotary and "as far as I know" there is no way to set the Rotary to a Value via Rules / MQTT / HTTP CMD or anything else.

If anybody has an Idea how to create the following,
- When I push the button on the Rotary the Counter should be set to 0 and start with 0 when the Rotary is moved.

thanks and best regards,

Stefan

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Rotary Encoder set values

#7 Post by Domosapiens » 21 Jun 2020, 23:27

30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rotary Encoder set values

#8 Post by chromo23 » 24 May 2021, 13:03

This is a bit older but since nothing has changed i want to present how i dealt with the issue.

I simply set the encoder limits to very large numbers (e.g. -9999999 and 9999999)

the i use this rule:

Code: Select all

on rotary#Counter do
if [rotary#Counter] > [count#Value] and [count#Dummy] < 30
Taskvalueset,6,1,[count#Dummy]+0.5
elseif [rotary#Counter] < [count#Value] and [count#Dummy] > 10
Taskvalueset,6,1,[count#Dummy]-0.5
endif
Taskvalueset,6,2,[rotary#Counter]
endon
As you can see, i compare the Rotary counter number with the stored value of the dummy device "count".
Depending on if it is lower or higher it in- or decreases the count#Dummy value and you can also constrain it.
Now you can simply use the Dummy value and do whatever you want with it....
(if you will ever reach the Rotary Counter limits you could let the device reboot for example)

zeroing would than simply be:

Code: Select all

on button#State=1 do
Taskvalueset,6,1,0      
endon

sartam
Normal user
Posts: 40
Joined: 13 Mar 2022, 21:25

Re: Rotary Encoder set values

#9 Post by sartam » 10 May 2022, 00:57

Hello. Is it possible to store the encoder value in non-volatile memory, so that after the power is turned off, the encoder, or variable, is assigned the same value as it was before the device was turned off?

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rotary Encoder set values

#10 Post by chromo23 » 10 May 2022, 13:07

Hi.. i did it like this:
I used the rotary-encoder to count up and down dummy values (for that i gave the rotary-encoder min and max values it will never reach)
Haven’t testet it because i wrote this from code fragments (the "on rotary#counter" part i still use and it works very well) and memory but it should be something like this:

Code: Select all

On Rotary#Counter do
 if [Rotary#Counter] > [count#Value] and [count#Dummy] < 30
  Taskvalueset,6,1,[count#Dummy]+0.5
 elseif [Rotary#Counter] < [count#Value] and [count#Dummy] > 15
  Taskvalueset,6,1,[count#Dummy]-0.5
 endif
 Taskvalueset,6,2,[Rotary#Counter] // that sets count#Value to the value of the rotary encoder
TimerSet,1,10 // set a timer so that the value is not written immediately to the levelplugin otherwise it cause way to many flash writes on every encoder rotation
endon

On Rules#Timer=1 do
write to the levelcontrol-plugin the dummy value
endon

On System#Boot do
 Taskvalueset,6,2,<the set value from the levelcontrol> // read the value at boot
endon
here the rotary settings:
Bildschirmfoto 2022-05-10 um 12.58.24.png
Bildschirmfoto 2022-05-10 um 12.58.24.png (50.49 KiB) Viewed 7034 times
Edit: just saw, that i posted most of it before :lol: but at least the "save it to the level plugin" part is new
Last edited by chromo23 on 10 May 2022, 20:31, edited 1 time in total.

sartam
Normal user
Posts: 40
Joined: 13 Mar 2022, 21:25

Re: Rotary Encoder set values

#11 Post by sartam » 10 May 2022, 17:17

That is, the dummy values ​​do not change after ESP EASY is turned off and on?

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

Re: Rotary Encoder set values

#12 Post by TD-er » 10 May 2022, 17:52

sartam wrote: 10 May 2022, 17:17 That is, the dummy values ​​do not change after ESP EASY is turned off and on?
The dummy values are lost when the ESP looses power.
They are kept in RTC memory, which gets restored at boot. Thus they survive a reboot or a crash, but not power cycle.

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rotary Encoder set values

#13 Post by chromo23 » 10 May 2022, 20:22

sartam wrote: 10 May 2022, 17:17 That is, the dummy values ​​do not change after ESP EASY is turned off and on?
Thats where the level control plugin comes into play.
https://espeasy.readthedocs.io/en/lates ... /P021.html

You can "misuse" it to store values permanently...


But since flash writes or better erase cycles are limited to 10k-100k you have to have something that prevents writing to often, like the timer in my demo code...
(Fortunately there is also a daily limit in espeasy that prevents excessive writing)

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

Re: Rotary Encoder set values

#14 Post by TD-er » 10 May 2022, 21:21

There is another way possible (not yet implemented in ESPEasy).
The idea I'm having is to add support for EEPROM or similar storage systems.
EEPROMs are available in I2C chips and allow for upto a million writes.
There are also types which are interface compatible with EEPROMs, but allow for near infinite writes. (10^12 or more)
And there is an EEPROM software layer in Arduino where you can assign a small piece of the flash for storing data.

The problem with NAND flash memory, as used on an ESP board, is that you can only change a 1 into a 0, not the other way around.
Reverting back to 1's needs an erase cycle of an entire block consisting of multiple pages (blocks are typically 8k in size)
The nr of erase cycles is really limited on NAND flash and is expressed in a few 1000's.

However, you can do some clever tricks on writing to NAND flash by only changing 1s to 0s.
For example you can keep track of the offset of writing a byte by changing the next bit to zero.
To store a 32 bit value you normally need 4 bytes.
But let's reserve 256 bytes for it.
Normally you can store 64 of those 32-bit values in it, so let's reserve the first 64 bit to mark where we are.
Then every 1 changed to 0 of those 64 bit can be used to show where we are with writing the latest value.
This way, you can write a new value 62 times and it only counts as 1 write for the wear of the flash.

Something like this is what I want to add to ESPEasy, so we can store some values that will survive a power loss.

User avatar
chromo23
Normal user
Posts: 821
Joined: 10 Sep 2020, 16:02
Location: germany

Re: Rotary Encoder set values

#15 Post by chromo23 » 10 May 2022, 21:31

TD-er wrote: 10 May 2022, 21:21 Something like this is what I want to add to ESPEasy, so we can store some values that will survive a power loss.
That would be awesome !!!

sartam
Normal user
Posts: 40
Joined: 13 Mar 2022, 21:25

Re: Rotary Encoder set values

#16 Post by sartam » 10 May 2022, 22:11

TD-er wrote: 10 May 2022, 21:21 There is another way possible (not yet implemented in ESPEasy).
The idea I'm having is to add support for EEPROM or similar storage systems.
EEPROMs are available in I2C chips and allow for upto a million writes.
There are also types which are interface compatible with EEPROMs, but allow for near infinite writes. (10^12 or more)
And there is an EEPROM software layer in Arduino where you can assign a small piece of the flash for storing data.
Yes. Very sorry. The problem that I'm trying to solve is not worth the complicated steps that you voiced. I posted a PCB project here, in which the mentioned EEPROM chip is already built in. And yes, in arduino you can write to memory with one command, as well as read it. I hope the respected TD-er will have time to add the plugin.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 25 guests