Change Device State

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
matzeeg3
Normal user
Posts: 14
Joined: 18 Mar 2020, 07:39

Change Device State

#1 Post by matzeeg3 » 18 Mar 2020, 07:43

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

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

Re: Change Device State

#2 Post by grovkillen » 18 Mar 2020, 08:11

Please post your settings and the rules so far.
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:

matzeeg3
Normal user
Posts: 14
Joined: 18 Mar 2020, 07:39

Re: Change Device State

#3 Post by matzeeg3 » 18 Mar 2020, 08:45

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

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

Re: Change Device State

#4 Post by grovkillen » 18 Mar 2020, 10:30

[oben_links#State]==0 isn't valid syntax. You need to use task value set...
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:

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

Re: Change Device State

#5 Post by TD-er » 18 Mar 2020, 10:32

That's not valid rules syntax.

Code: Select all

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

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

Re: Change Device State

#6 Post by TD-er » 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?

matzeeg3
Normal user
Posts: 14
Joined: 18 Mar 2020, 07:39

Re: Change Device State

#7 Post by matzeeg3 » 18 Mar 2020, 10:39

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

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

Re: Change Device State

#8 Post by grovkillen » 18 Mar 2020, 13:16

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?
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:

matzeeg3
Normal user
Posts: 14
Joined: 18 Mar 2020, 07:39

Re: Change Device State

#9 Post by matzeeg3 » 18 Mar 2020, 13:26

i just read the TaskValueSet.
but i´m not sure if i understand it the right way

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

Re: Change Device State

#10 Post by grovkillen » 18 Mar 2020, 13:28

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.
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:

matzeeg3
Normal user
Posts: 14
Joined: 18 Mar 2020, 07:39

Re: Change Device State

#11 Post by matzeeg3 » 18 Mar 2020, 13:44

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 :)

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

Re: Change Device State

#12 Post by TD-er » 18 Mar 2020, 14:30

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.

matzeeg3
Normal user
Posts: 14
Joined: 18 Mar 2020, 07:39

Re: Change Device State

#13 Post by matzeeg3 » 18 Mar 2020, 14:55

i want to build an hardware switch.
like the attached image
Attachments
20200318_145326.jpg
20200318_145326.jpg (346.36 KiB) Viewed 863 times

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

Re: Change Device State

#14 Post by TD-er » 18 Mar 2020, 16:21

I meant the OpenHAB controller in ESPEasy.

matzeeg3
Normal user
Posts: 14
Joined: 18 Mar 2020, 07:39

Re: Change Device State

#15 Post by matzeeg3 » 18 Mar 2020, 16:24

i´m sorry where did i find it?

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

Re: Change Device State

#16 Post by TD-er » 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.

matzeeg3
Normal user
Posts: 14
Joined: 18 Mar 2020, 07:39

Re: Change Device State

#17 Post by matzeeg3 » 18 Mar 2020, 16:41

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?

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

Re: Change Device State

#18 Post by TD-er » 18 Mar 2020, 22:18

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.

matzeeg3
Normal user
Posts: 14
Joined: 18 Mar 2020, 07:39

Re: Change Device State

#19 Post by matzeeg3 » 18 Mar 2020, 22:56

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"
Attachments
devices.png
devices.png (73.96 KiB) Viewed 813 times
controller.png
controller.png (36.82 KiB) Viewed 813 times

matzeeg3
Normal user
Posts: 14
Joined: 18 Mar 2020, 07:39

Re: Change Device State

#20 Post by matzeeg3 » 20 Mar 2020, 07:43

Nobody an idear how i can change the value of my input switch without pushing the botton

matzeeg3
Normal user
Posts: 14
Joined: 18 Mar 2020, 07:39

Re: Change Device State

#21 Post by matzeeg3 » 24 Mar 2020, 13:16

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

SawwaOff
Normal user
Posts: 5
Joined: 19 Mar 2020, 19:12

Re: Change Device State

#22 Post by SawwaOff » 24 Mar 2020, 17:53

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 457 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!

matzeeg3
Normal user
Posts: 14
Joined: 18 Mar 2020, 07:39

Re: Change Device State

#23 Post by matzeeg3 » 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

SawwaOff
Normal user
Posts: 5
Joined: 19 Mar 2020, 19:12

Re: Change Device State

#24 Post by SawwaOff » 25 Mar 2020, 17:31

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

matzeeg3
Normal user
Posts: 14
Joined: 18 Mar 2020, 07:39

Re: Change Device State

#25 Post by matzeeg3 » 25 Mar 2020, 17:32

Can you post your rule and a part of your life when sending multiple times?

SawwaOff
Normal user
Posts: 5
Joined: 19 Mar 2020, 19:12

Re: Change Device State

#26 Post by SawwaOff » 25 Mar 2020, 19:58

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

matzeeg3
Normal user
Posts: 14
Joined: 18 Mar 2020, 07:39

Re: Change Device State

#27 Post by matzeeg3 » 25 Mar 2020, 21:33

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?

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests