• 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
Running script one time.
#1
Hi,
Is it possible to just run a script via the webgui?
I mean, like the program protocol but without the need of a service or "monitoring" PIDs, etc.
Thanks.
 
Reply
#2
No, use the program protocol Smile
 
Reply
#3
Yes curlymo, sorry, I posted before seeing the Development section.
The "dummy" example and the "program" gave me some ideas.
Thanks. Nice work BTW.
 
Reply
#4
maybe you can post your final result here for other people with the same question...little bit give and take Big Grin

Send from tapatalk phone...
 
Reply
#5
@creamers
assuming that will work Smile
I'll run some tests and if it is worth it, I'll post it.
 
Reply
#6
I am using the program protocol to sun a simple python script to wake up my NAS via WOL when not at home:
Code:
"WOL": {
                        "protocol": [ "program" ],
                        "id": [{
                                "name": "WOL"
                        }],
                        "program": "/home/pi/wakeNAS.py",
                        "arguments": "",
                        "stop-command": "python /home/pi/wakeNAS.py",
                        "start-command": "python /home/pi/wakeNAS.py",
                        "state": "stopped",
                        "pid": 0
                }
I think I could have left the "program" and "stop-command" objects empty. Easy as a pi!
 
Reply
#7
Same question: need a simple "run script" button without monitoring the PID.

I want to switch my webradio on/off (Hama IR110). That's possible via web calls so I wrote a simple Python script (see link below if you're interested).

Simply switching on/off works using the program protocol and a workaround as follows.

So the question is: is there a device element/protocol like a simple push button (no switch having on/off or play/stop state) that simply calls a script - just fire and forget?

config.json:
Code:
{
        "devices": {
                "living_radio": {
                        "protocol": [ "program" ],
                        "id": [{
                                "name": "living_radio"
                        }],
                        "program": "/usr/bin/python",
                        "arguments": "/home/osmc/pilight-programs/radio.py 192.168.0.127 1",
                        "stop-command": "/home/osmc/pilight-programs/radio.py 192.168.0.127 0 &",
                        "start-command": "/home/osmc/pilight-programs/radio.py 192.168.0.127 1 &",
                        "state": "stopped",
                        "pid": 0
                }
        },
        "rules": {
                "rule_living_radio_on": {
                        "rule": "IF living_radio.state IS on THEN switch DEVICE living_radio TO running",
                        "active": 1
                },
                "rule_living_radio_off": {
                        "rule": "IF living_radio.state IS off THEN switch DEVICE living_radio TO stopped",
                        "active": 1
                }
        },
        "gui": {
                "living_radio": {
                        "name": "Radio Living Room",
                        "group": [ "Radio" ]
                }
        }
}

See /home/osmc/pilight-programs/radio.py here

^^ Everything below line 31 is a workaround for the monitoring: The script doesn't exit until it is called again with the switch off argument.

The big problem is that I also switch the radio on/off using the hardware buttons or its remote control. Then, pilight cannot detect its state (running or stopped).

Then, rules like "switch off everything" don't apply because pilight thinks that the radio program is already stopped and doesn't seem to send the stop-command. See a sample rule here:

Code:
"rule_all_off": {
        "rule": "IF all.state IS off THEN switch DEVICE light1 AND light2 TO off AND switch DEVICE living_radio TO stopped",
        "active": 1
}

So it only works if I switched the radio on using pilight first.
 
Reply
#8
I created the following workaround which works fine now:
  1. For each signal on and off I created a separate device with the program protocol where the start command is the same as the stop command.
  2. I created a dummy switch device (generic_switch) that's visible in the GUI/app.
  3. I'm using 2 separate rules, one for on and one for off as described above.
The trick is to have 2 program devices. So pilight doesn't care about the program's state.

The problem before was that pilight doesn't send the stop-command if the program is not in the "running" state. So you couldn't switch off a simple program that is no service/daemon because it's running only a few seconds and terminates itself.
 
Reply
#9
(10-20-2015, 07:27 PM)droptix Wrote: I created the following workaround which works fine now:
  1. For each signal on and off I created a separate device with the program protocol where the start command is the same as the stop command.
  2. I created a dummy switch device (generic_switch) that's visible in the GUI/app.
  3. I'm using 2 separate rules, one for on and one for off as described above.
The trick is to have 2 program devices. So pilight doesn't care about the program's state.

The problem before was that pilight doesn't send the stop-command if the program is not in the "running" state. So you couldn't switch off a simple program that is no service/daemon because it's running only a few seconds and terminates itself.

Can you post an example of the workaround please.
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  Wrong time after switch from DST Rschnauzer 2 346 10-29-2018, 06:00 PM
Last Post: Rschnauzer
  How to check if a time is between two times? rorie 4 493 10-18-2018, 07:06 AM
Last Post: curlymo
  Date/time out of sync with pi system time wimd 7 2,131 04-25-2017, 11:30 AM
Last Post: Niek
  Running pilight offline Aweponken 11 5,437 07-20-2015, 07:12 PM
Last Post: Aweponken
  Execute python script from Generic Switch? panton 4 3,362 04-28-2015, 07:58 AM
Last Post: curlymo
  Use pilight to run a script on binary receive? scorpydude 6 4,513 01-15-2015, 01:51 PM
Last Post: curlymo
  Sending and receiving at the same time geerttttt 2 1,763 07-09-2014, 01:12 AM
Last Post: scorpydude
  Start command/script on pulse receive wous 10 9,920 12-24-2013, 09:39 PM
Last Post: bultje76

Forum Jump:


Browsing: 1 Guest(s)