Setting a dummy device value in rule

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
garnold
Normal user
Posts: 93
Joined: 17 Jun 2019, 03:59

Setting a dummy device value in rule

#1 Post by garnold » 15 Mar 2021, 13:55

I'm sure this one is an easy one and I'm just not searching the forum and docs correctly. I need to store a value that can be queried later on from a REST call (like sensorupdate). My idea is to simply store what I need in a dummy device. I cannot find the proper call to set the value of this device in a rule. The dummy device is looking to store a 0 or 1. So basically, when one event fires store a 0 in dummy device and when another event fires store a 1 in dummy device. I'm sure this is easy but I just can't seem to find the call. Thank you

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

Re: Setting a dummy device value in rule

#2 Post by TD-er » 15 Mar 2021, 14:25

You can give the event command via HTTP and include a number of eventvalues.
For example the command:

Code: Select all

Event,eventname=1,2,3,4
If you enter it from the command field on the Tools page, you'll see the encoded URL:

Code: Select all

http://192.168.10.151/tools?cmd=Event%2Ceventname%3D1%2C2%2C3%2C4
The "eventname" is a name you can pick yourself and act on it in the rules:

Code: Select all

on eventname do
  taskvalueset,1,1,%eventvalue1%
  taskvalueset,1,2,%eventvalue2%
  taskvalueset,1,3,%eventvalue3%
  taskvalueset,1,4,%eventvalue4%
endon
Just be aware that %eventvalue3% for example will not be replaced by its value if less than 3 eventvalues are given. (same for %eventvalue2% etc)
See also https://espeasy.readthedocs.io/en/lates ... skvalueset

garnold
Normal user
Posts: 93
Joined: 17 Jun 2019, 03:59

Re: Setting a dummy device value in rule

#3 Post by garnold » 15 Mar 2021, 14:30

Excellent, I'll give this a try. So when setting the value of the device I don't call it like this....

[DummyDevice#value] = someValue

I need to reference the device via the task number and the number of the specific item I want to set within that task. Is this correct? I'm pretty sure that is what you meant by the below but wanted to confirm.

taskvalueset,1,1,%eventvalue1%

Thank you again!

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

Re: Setting a dummy device value in rule

#4 Post by TD-er » 15 Mar 2021, 14:37

Yep, dummy task values must be set using taskvalueset command.
You can "read" them via [taskvaluename#variablename] syntax.

garnold
Normal user
Posts: 93
Joined: 17 Jun 2019, 03:59

Re: Setting a dummy device value in rule

#5 Post by garnold » 15 Mar 2021, 14:38

Perfect! Thank you very much!

garnold
Normal user
Posts: 93
Joined: 17 Jun 2019, 03:59

Re: Setting a dummy device value in rule

#6 Post by garnold » 15 Mar 2021, 15:44

I just wanted to post my final results just incase someone reads this thread and has the same reqs.

So now I can pass in the blow url to open the vent
http://192.168.86.52/control?cmd=event,controlVent=1

and to close the vent
http://192.168.86.52/control?cmd=event,controlVent=0

and I can get the status of the vent with
http://192.168.86.52/json?view=sensorupdate

I check the value being sent in from the URL. Based on that value I open or close the vent as well as set a dummy device which I can query later. This dummy device acts as a method of allowing me to run a REST call into the ESPEasy and get the vent's status.

Code: Select all

on controlVent do
  if %eventvalue1%=1
   LogEntry, 'Vent Open'
   servo,1,14,90
   taskvalueset,2,1,%eventvalue1%
  else
   LogEntry, 'Vent Closed'
   servo,1,14,0
   taskvalueset,2,1,%eventvalue1%
  endif
endon
Thank you again TD-er for all the help!

Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests