Page 1 of 1

Change Device State

Posted: 18 Mar 2020, 07:43
by matzeeg3
Hi everybody.

i hope i don´t ask a very stuoid question but:
i make a rule witch is triggert by an mqtt imoirt.
that is working fine. so the first step what the incoming rule should do works fine.
in additional to this step i would like to change the Device-State.
Its a Switch Named "unten_links" and the Values are State 1 or 0.
I wan´t to change the state of this items.
but i don´t know how to do it in the rule or better i don´t find a solution.

i hope someone can help me.

Kind regards
Matthias

Re: Change Device State

Posted: 18 Mar 2020, 08:11
by grovkillen
Please post your settings and the rules so far.

Re: Change Device State

Posted: 18 Mar 2020, 08:45
by matzeeg3
Hi
here is my rule:
on MQTTIN#State1 do
if [MQTTIN#State1]=0
GPIO,15,0
[oben_links#State]==0
else
GPIO,15,1
endif
endon

The Switch oben_links is a normal switch

Re: Change Device State

Posted: 18 Mar 2020, 10:30
by grovkillen
[oben_links#State]==0 isn't valid syntax. You need to use task value set...

Re: Change Device State

Posted: 18 Mar 2020, 10:32
by TD-er
That's not valid rules syntax.

Code: Select all

on MQTTIN#State1 do
  GPIO,15,[MQTTIN#State1]
endon
Maybe this will work?

Re: Change Device State

Posted: 18 Mar 2020, 10:32
by TD-er
grovkillen wrote:
18 Mar 2020, 10:30
[oben_links#State]==0 isn't valid syntax. You need to use task value set...
Does TaskValueSet work on all plugins?

Re: Change Device State

Posted: 18 Mar 2020, 10:39
by matzeeg3
i wan´t to set the value from:
[MQTTIN#State1]
i don´t want to use it.
i wan´t to change the gpio like it is and that worked.
but i wan´t to change the state of the Switch
so if the rule trigger switch state change from 1 to 0 via MQTT

Re: Change Device State

Posted: 18 Mar 2020, 13:16
by grovkillen
TD-er wrote:
18 Mar 2020, 10:32
grovkillen wrote:
18 Mar 2020, 10:30
[oben_links#State]==0 isn't valid syntax. You need to use task value set...
Does TaskValueSet work on all plugins?
I think so yes?

Re: Change Device State

Posted: 18 Mar 2020, 13:26
by matzeeg3
i just read the TaskValueSet.
but i´m not sure if i understand it the right way

Re: Change Device State

Posted: 18 Mar 2020, 13:28
by grovkillen
Sorry but I have a hard time understand what your goal is. Please try to make a concise description what you're trying to achieve.

Re: Change Device State

Posted: 18 Mar 2020, 13:44
by matzeeg3
Ok here my case.
i build a 4 butto switch with 4 led with espeasy
if i push a botton i send a http request to openhab witch chane a switch there.
like this:

Code: Select all

on oben_links#State do
SendToHTTP x.x.x.x,8080,/classicui/CMD?sw001=[oben_links#State#O#P1]
endon
Openhab than did everything fine and push an mqtt update to my broker
ESPEASY grab that and turn on / turn off the LEDs
like this.

Code: Select all

on MQTTIN#State1 do
 if [MQTTIN#State1]=0
  GPIO,15,0
 else
  GPIO,15,1
 endif
endon
now you can change the switch in openhab itself and if that happend the led will turn on or off but in this way the state in espeasy is different than in openhab.
no i want to greb the same state as for the led and change the "Value" of the "State" from the Button.
hope now there is a way to understand it.
thanke :)

Re: Change Device State

Posted: 18 Mar 2020, 14:30
by TD-er
Why don't you use the OpenHAB controller then?
The Domoticz and OpenHAB controllers have some logic in them to act on responses sent via the controller for some specific plugins.
The switch plugin is one of them.

Re: Change Device State

Posted: 18 Mar 2020, 14:55
by matzeeg3
i want to build an hardware switch.
like the attached image

Re: Change Device State

Posted: 18 Mar 2020, 16:21
by TD-er
I meant the OpenHAB controller in ESPEasy.

Re: Change Device State

Posted: 18 Mar 2020, 16:24
by matzeeg3
i´m sorry where did i find it?

Re: Change Device State

Posted: 18 Mar 2020, 16:29
by TD-er
See the documentation: https://espeasy.readthedocs.io/en/lates ... oller.html
It is the controller tab in the web interface.

Re: Change Device State

Posted: 18 Mar 2020, 16:41
by matzeeg3
TD-er wrote:
18 Mar 2020, 16:29
See the documentation: https://espeasy.readthedocs.io/en/lates ... oller.html
It is the controller tab in the web interface.
i use MQTT to send and recive data but how can i get the "Generic Switch" Worked with it to send an recive data?

Re: Change Device State

Posted: 18 Mar 2020, 22:18
by TD-er
This is quite basic info on how to operate ESPEasy.

You create a controller (on the controller tab) and remember its ID nr (1, 2 or 3) and make sure it is enabled.
Then, as soon as you have an enabled controller, you will see it also appear on the config page of a specific task (devices tab).
There you select the controller you would like to send data to (the 1, 2 or 3) and save.
N.B. A task can have 0 ... 3 controllers.
N.B.2. A task is using a plugin and multiple tasks can use the same plugin (e.g. multiple instances of the Dallas 1-wire temp sensor)

When a task is run, it will deliver some new values and hand them over to the selected controller of that task.
This controller will then make sure the data is delivered to the configured end point. For example Domoticz or OpenHAB MQTT, some HTTP server, etc.

A task is run at either a set interval (see task config page, almost at the bottom) or when you call taskrun from the rules.

Re: Change Device State

Posted: 18 Mar 2020, 22:56
by matzeeg3
yes all you write here is what i do.
i addad some screenshots.
but i want to change the state of the switches "device first 4" via MQTT not Send. i would like to recive"

Re: Change Device State

Posted: 20 Mar 2020, 07:43
by matzeeg3
Nobody an idear how i can change the value of my input switch without pushing the botton

Re: Change Device State

Posted: 24 Mar 2020, 13:16
by matzeeg3
i get it working, here is my solution:

Code: Select all

on oben_links#State do
SendToHTTP x.x.x.x,8080,/classicui/CMD?tuyasw001=[oben_links#State#O#P1]
  GPIO,12,1
endon

on oben_rechts#State do
SendToHTTP x.x.x.x,8080,/classicui/CMD?tuyasw002=[oben_rechts#State#O#P1]
endon

on unten_links#State do
SendToHTTP x.x.x.x,8080,/classicui/CMD?tuyasw003=[unten_links#State#O#P1]
endon

on unten_rechts#State do
SendToHTTP x.x.x.x,8080,/classicui/CMD?tuyasw004=[unten_rechts#State#O#P1]
endon

on MQTTIN#State1 do
 if [MQTTIN#State1]=0
  GPIO,15,0
 else
  GPIO,15,1
 endif
endon

on MQTTIN#State2 do
 if [MQTTIN#State2]=0
  GPIO,2,0
GPIO,2,0
 else
  GPIO,2,1
 endif
endon



on MQTTIN#State3 do
 if [MQTTIN#State3]=0
  GPIO,4,0
 else
  GPIO,4,1
 endif
endon

on MQTTIN#State4 do
 if [MQTTIN#State4]=0
  GPIO,0,0
 else
  PWM,0,100
 endif
endon

on MQTTIN#State1 do
 if [MQTTIN#State1]= 0 and [oben_links#State] = 1
  GPIO,12,0
  timerSet,1,1
 endif
endon

on MQTTIN#State1 do
 if [MQTTIN#State1]= 1 and [oben_links#State] = 0
  GPIO,12,0
  timerSet,1,1
 endif
endon

on MQTTIN#State2 do
 if [MQTTIN#State2]= 0 and [oben_rechts#State] = 1
  GPIO,5,0
  timerSet,1,1
 endif
endon

on MQTTIN#State2 do
 if [MQTTIN#State2]= 1 and [oben_rechts#State] = 0
  GPIO,5,0
  timerSet,1,1
 endif
endon

on MQTTIN#State3 do
 if [MQTTIN#State3]= 0 and [unten_links#State] = 1
  GPIO,12,0
  timerSet,1,1
 endif
endon

on MQTTIN#State3 do
 if [MQTTIN#State3]= 1 and [unten_links#State] = 0
  GPIO,12,0
  timerSet,1,1
 endif
endon

on MQTTIN#State4 do
 if [MQTTIN#State4]= 0 and [unten_rechts#State] = 1
  GPIO,13,0
  timerSet,1,1
 endif
endon

on MQTTIN#State4 do
 if [MQTTIN#State4]= 1 and [unten_rechts#State] = 0
  GPIO,13,0
  timerSet,1,1
 endif
endon

on Rules#Timer=1 do
GPIO,12,1
GPIO,14,1
GPIO,13,1
GPIO,5,1
endon

Re: Change Device State

Posted: 24 Mar 2020, 17:53
by SawwaOff
Hi for everybody!

I need help in devices states send to Domoticz.

When I enable sending the state from the Device setting page, status value (1 or 0) sending in Domotics multiple times ,
while the notification set in Domoticzis constantly triggered and sends a lot of messages with the same status.

But i need ONLY ONE message with changed status!
1.JPG
1.JPG (56.76 KiB) Viewed 2224 times
I tryed to create my one rules in ESPEasy, but faced the same problem - an event that should be sent once, when switching the relay, is sent multiple times ! :roll:

on Relay2#state do
SendToHTTP 192.168.1.42,8080,/json.htm?type=command&param=udevice&idx=2&nvalue=[Relay2#state]
endon

Please, help!

Re: Change Device State

Posted: 24 Mar 2020, 21:21
by matzeeg3
Why you have an interval set it to 0 you don't need it for the switch maybe then it stops sending

Re: Change Device State

Posted: 25 Mar 2020, 17:31
by SawwaOff
matzeeg3 wrote:
24 Mar 2020, 21:21
Why you have an interval set it to 0 you don't need it for the switch maybe then it stops sending
I set 0, the relay status is still sent many times

Re: Change Device State

Posted: 25 Mar 2020, 17:32
by matzeeg3
Can you post your rule and a part of your life when sending multiple times?

Re: Change Device State

Posted: 25 Mar 2020, 19:58
by SawwaOff
matzeeg3 wrote:
25 Mar 2020, 17:32
Can you post your rule and a part of your life when sending multiple times?
on Relay1#state do
SendToHTTP 192.168.xx.xx,8080,/json.htm?type=command&param=udevice&idx=10&nvalue=[Relay1#state]
timerSet,1,10
endon

Re: Change Device State

Posted: 25 Mar 2020, 21:33
by matzeeg3
SawwaOff wrote:
25 Mar 2020, 19:58
on Relay1#state do
SendToHTTP 192.168.xx.xx,8080,/json.htm?type=command&param=udevice&idx=10&nvalue=[Relay1#state]
timerSet,1,10
endon
What happend if timerSet,1,10 is ready?
Can you post a part of your Log? Tools -> Log?