Rules and Dummy Device

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
nosehook
New user
Posts: 2
Joined: 03 Mar 2024, 09:59

Rules and Dummy Device

#1 Post by nosehook » 03 Mar 2024, 10:10

I am a bit new in Rules and am trying the following:

Via the call http://192.168.50.34/control?cmd=TaskValueSet%204,1,1 I want to set a dummy device (Name: DummySwitch, output data type: switch, value 1 name: Dummy) to 1.
So far, this works.

Furthermore, I want to automatically set the value back to 0.
I tried to do this via rules with several options like:

Code: Select all

 on DummySwitch do
    TaskValueSet 4,1,0
 Endon
So far, this does not seem to work. Apparently I am not using the right syntax or terms.
What am I doing wrong?

Thanks in advance!

User avatar
Ath
Normal user
Posts: 3519
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules and Dummy Device

#2 Post by Ath » 03 Mar 2024, 13:43

nosehook wrote: 03 Mar 2024, 10:10 Furthermore, I want to automatically set the value back to 0.
I tried to do this via rules with several options like:

Code: Select all

 on DummySwitch do
    TaskValueSet 4,1,0
 Endon
So far, this does not seem to work. Apparently I am not using the right syntax or terms.
What am I doing wrong?
- Have you seen the "Event: DummySwitch#Dummy=1" appear in the log output?
- Do you have other rules defined that handle "on DummySwitch#Dummy do" (optionally with =0 or =1 attached)?
/Ton (PayPal.me)

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

Re: Rules and Dummy Device

#3 Post by TD-er » 03 Mar 2024, 18:58

If you name the task "Dummy" and the taskvalue is called "Switch", then the event will be "Dummy#Switch=...." with on the dots a taskvalue.
Or if you checked to send all values in a single event, the event will be "Dummy#All=...,...,..." with comma separated the different task values (or just 1 if the task has only a single taskvalue)
Just keep in mind the "All" them.

So better keep an eye on the logs when you expect an event as the full event will be shown in the (loglevel: Info) logs.

User avatar
Ath
Normal user
Posts: 3519
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Rules and Dummy Device

#4 Post by Ath » 03 Mar 2024, 21:19

Ah, the case with the Dummy plugin is that it doesn't generate events (after the initial event when started) when the Interval is set to 0.
So if you need a an event to be generated, you should use another member of the TaskValueSet command family: TaskValueSetAndRun:

Code: Select all

On remoteSwitch Do
  TaskValueSetAndRun,DummySwitch,Dummy,%eventvalue1% // If no argument is provided, 0 is used, and the value is sent to controllers & rules
  LogEntry,'==> DummySwitch is set to %eventvalue1%'
Endon

On DummySwitch Do
  TaskValueSet,DummySwitch,Dummy,0
  LogEntry,'==> DummySwitch is reset to 0'
Endon
A few more remarks:
- It's more universal to use the Taskname/Valuename for setting a Dummy Device, so the code is more portable, and not bound to a specific task number
- It's better to use an Event, and a matching event-handler in rules, to change a device value from an external source, to make it more of a 'black box', and easier to change. Also, in rules you can use multiple commands for a single event, if needed (like the logentry I added)

The external command would then be: http://192.168.50.34/control?cmd=event,remoteSwitch=1 (your browser could change that to: cmd=event%2CremoteSwitch%3D1)
/Ton (PayPal.me)

nosehook
New user
Posts: 2
Joined: 03 Mar 2024, 09:59

Re: Rules and Dummy Device

#5 Post by nosehook » 10 Mar 2024, 20:40

Thank you! That clarifies the issue. Much appreciated!
Ath wrote: 03 Mar 2024, 21:19 Ah, the case with the Dummy plugin is that it doesn't generate events (after the initial event when started) when the Interval is set to 0.
So if you need a an event to be generated, you should use another member of the TaskValueSet command family: TaskValueSetAndRun:

Code: Select all

On remoteSwitch Do
  TaskValueSetAndRun,DummySwitch,Dummy,%eventvalue1% // If no argument is provided, 0 is used, and the value is sent to controllers & rules
  LogEntry,'==> DummySwitch is set to %eventvalue1%'
Endon

On DummySwitch Do
  TaskValueSet,DummySwitch,Dummy,0
  LogEntry,'==> DummySwitch is reset to 0'
Endon
A few more remarks:
- It's more universal to use the Taskname/Valuename for setting a Dummy Device, so the code is more portable, and not bound to a specific task number
- It's better to use an Event, and a matching event-handler in rules, to change a device value from an external source, to make it more of a 'black box', and easier to change. Also, in rules you can use multiple commands for a single event, if needed (like the logentry I added)

The external command would then be: http://192.168.50.34/control?cmd=event,remoteSwitch=1 (your browser could change that to: cmd=event%2CremoteSwitch%3D1)

Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests