• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pass dimlevel as argument to program device
#1
I included my radio in pilight because it has a web API. Currently it just has an on/off switch by calling a script (defined in a device using the program protocol). That's working fine.

Now I wanted to add volume control. I was thinking of a generic_dimmer device which calls a program when the state is changed. My radio has 30 volume levels.

A solution that could work is to define 30 rules like "IF radio.dimlevel == 1 THEN switch radio_volume_1 TO running". So I would create 30 program devices as well and the result is a quite long config.

I was wondering if it's possible to pass the dimlevel as argument to the program's start-command, maybe in combination with a rule like "IF radio.dimlevel > 0 THEN switch radio_volume TO running PARAMS '-set %radio.dimlevel%'"

Any ideas?
 
Reply
#2
Afaik, this isn't available yet, although I've heard about wishes for variables like that in rules before somewhere. This would be very useful, we'll have to see what happens after the pilight rewrite Smile
For now you will just have to create 30 rules though…
 
Reply
#3
A workaround would be letting the program actually use the pilight API to retrieve the last dimlevel set in the config. That would reduce this to a single rule.
 
Reply
#4
I also thought about it. I'm already using the API for simple things but I didn't find an answer how to get a special device state or dimlevel via pilight's API.

The only idea I had was to retrieve the whole config as JSON (I guess the return value is the latest config state from memory) and then extract the dimlevel value.

The main problem will be network latencies when adjusting the dimmer because then 2 API calls are done.

Another idea was to use a generic_screen and just have 2 program devices, one for vol+ and the other vol-. But the problem with the screen is that it has only 2 fixed states (up or down) and when I pushed up once then the state is set to up and following up's are not honored (because the state actually didn't change).

I read about a switch without a fixed state here in the forum but it's not possible to use the same idea for a screen :-)
 
Reply
#5
That's a good idea

Yes, the response to getting the config is the entire latest config.json from memory, which you can then parse by the keys to get the value you want. I've done it in python before, if you have questions Smile
The pilight API is fast, I don't think there will be issues with network latencies.

The first solution with the API seems smoother and less of a hack, as there is no single-fire button for the webGUI.
 
Reply
#6
Shouldn't be a problem using Python... Thank you.
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  [Solved] On and Off for one device in one rule Oliver 3 449 10-28-2019, 06:55 PM
Last Post: Oliver
  Can't switch Relay device by rules: Error switch.lua:77 wobbi 6 1,102 07-31-2018, 06:25 AM
Last Post: curlymo
  Rule with&without device. One working not the other... Tamadite 9 1,396 07-24-2018, 08:55 AM
Last Post: curlymo
  Program can't be set to state running Gisto 7 1,298 07-17-2018, 12:51 PM
Last Post: Gisto
  Problem with executing bash script via rule/program dYna 1 1,039 02-15-2018, 09:06 PM
Last Post: dYna
  Always trigger event on any device state Phil 8 2,422 03-22-2017, 07:30 PM
Last Post: Phil
  Dimlevel to set Alarm Clock Jonsibua 3 1,431 02-10-2017, 05:38 AM
Last Post: terrar
  [Solved ]Turn off device at random time manmetdehamer 4 2,212 07-27-2016, 03:35 PM
Last Post: manmetdehamer
  ERROR: rule #21 invalid: variable "label" of device "WindMax" cannot be used in even koos147 2 1,915 04-02-2016, 10:24 PM
Last Post: koos147
  action: program bazb 16 8,217 03-31-2016, 09:14 AM
Last Post: Niek

Forum Jump:


Browsing: 1 Guest(s)