Option to run system commands from automagically
Hi,
It would be great to have the option of creating 'devices' that run shell scripts on the system, write to a file or fetch a web page.
This would be sort of the opposite of the data fetcher, giving a way to trigger software action when some sensor reach a certain value are or a switch is trigerred.
Example: when I 'double click' on off on the remote next to my bed, automagically turns off all lights in the house. It would be great if it could as well run a script that scans the network and turn off computers that I forgot to shutdow.
Comments (3)
-
-
This feature would open up a world of use cases. My closest project where this would be useful is to put a nexa remote next to my light switches to control the sonos audio in that room using a simple sonos python wrapper.
I would love to implement this myself but I did not fully get my head around what needs to be implemented looking at the code. Some pointers in the right direction would be appreciated.
-
Just want to share a the plugin I made to make this happen.
This is the code I put in sites/plugins/command.py
from django.db import models import signals.models import Queue import os from settings.models import getSettings PLUGIN_NAME = 'command' debug = False workQueue = Queue.Queue() global currentSettings currentSettings = {} def signalHandler(signal): global currentSettings if not currentSettings or signal.content.strip() == PLUGIN_NAME + ',configuration,changed': currentSettings = getSettings(PLUGIN_NAME) print 'configuration updated' print currentSettings if signal.content == 'terminate': workQueue.put(None) elif signal.content.startswith('command:'): workQueue.put(signal.content[8:].strip()) def threadFunc(): keepRunning = True while(keepRunning): try: command = workQueue.get() if command == None: print 'Got a none from command workQueue' workQueue.task_done() keepRunning = False continue if debug: print 'Runnning command' print 'Command:', command os.system(command) workQueue.task_done() except: print 'Error executing command command' if debug: raise def init():
With this plugin it is possible to run any script with the signal: "command:/path/to/command"
- Log in to comment
+1 An option like this could also trigger ssh commands to shutdown/hibernate other computers in the network, as a very simple option send a suhtdown command in a 1liner