Page 1 of 1

Real time rotary encoder mqtt publish!

Posted: 20 Dec 2017, 04:07
by Osmi
Hello everybody!
I have Wemos D1 with latest test build connected to rotary encoder. I am controlling my receiver volume trough OpenHab mqtt binding. It is working well.
I have two questions:
1. Is it possible to set Espeasy to publish encoder status in real time(fast)?
2. Can I set Espeasy not to publish initial 0 state of encoder on boot, and set it to receive volume topic(in case of IR remote)?

Lets say that after boot, Wemos subscribe to a volume topic, then receive volume status from broker(retained flag), then update the rotary value(from 0 to a new value).

Re: Real time rotary encoder mqtt publish!

Posted: 20 Dec 2017, 06:12
by grovkillen
Yes you can do both using rules. Please study the wiki and get back here if you need further assistance.

Re: Real time rotary encoder mqtt publish!

Posted: 15 Mar 2018, 03:37
by Osmi
OK!
I am not very good at programing. let me start with, do not publish initial state 0 with mqtt...

On System#Boot
if volume#set=0
"do not publish 0"/dont know what to put here
endon

Re: Real time rotary encoder mqtt publish!

Posted: 15 Mar 2018, 09:49
by leel1967l
Osmi wrote: 15 Mar 2018, 03:37 OK!
I am not very good at programing. let me start with, do not publish initial state 0 with mqtt...

On System#Boot
if volume#set=0
"do not publish 0"/dont know what to put here
endon
Hi,
how did you solve this problem?
I haven't been able to set the initial value of a rotary encoder.

Re: Real time rotary encoder mqtt publish!

Posted: 15 Mar 2018, 09:55
by grovkillen
I think you should store the value using a dummy device and only let the rotary encoder do the addition / subtraction from that value.

Re: Real time rotary encoder mqtt publish!

Posted: 14 Sep 2019, 03:04
by gtgt
Dummy device may not be a solution, if he wants to allow set volume to 0, but later...

To not set 0 value, it's easier to not send the device value automatically (uncheck "Send to controller" at device edit) and create a rule to publish (but with condition):

Code: Select all

on volume#set>0 do
  Publish %sysname%/volume/set,[volume#set]
endon
However it will not solve much, because when you rotate, then the volume will send value from 1, even the volume on the other side is higher.
You have to receive value from the topic, not just send. To do this, you need MQTT Import device. Name it to "import" for example, set topic and value to "volume", then rewrite the rules:

Code: Select all

on import#volume do
  // assuming the first device/task is the rotary encoder
  TaskValueSet 1,1,[import#volume]
emdon

on volume#set do
  Publish %sysname%/import/volume,[volume#set]
  // assuming the second device/task is the MQTT import. This update may not be necessary, since the value will "come back" via mqtt anyway.
  TaskValueSet 2,1,[volume#set]
endon
You will need modify the topic on the other side from volume/set -> import/volume.

Re: Real time rotary encoder mqtt publish!

Posted: 03 Jan 2024, 10:32
by Osmi
Hello. Thanks to the encwrite function and everyone who contributed to this, I managed to program it. Happy New Year 2024 to everyone.

Code: Select all

on mqtt#volume do
    encwrite,[mqtt#volume]
endon

on volume#value do
    Publish %sysname%/volume,[volume#value]
    TaskValueSet 4,1,[volume#value]
endon