option to run cmd on switch open
This commit is contained in:
		@@ -27,7 +27,8 @@
 | 
			
		||||
            "name": "",
 | 
			
		||||
            "uniqueId": "",
 | 
			
		||||
            "valueKey": "open",
 | 
			
		||||
            "influxKey": "state"
 | 
			
		||||
            "influxKey": "state",
 | 
			
		||||
            "openScript": "this is optional"
 | 
			
		||||
        }
 | 
			
		||||
    ]
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
import axios from 'axios'
 | 
			
		||||
import WebSocket from 'ws'
 | 
			
		||||
import fs from 'fs'
 | 
			
		||||
import exec from 'child_process'
 | 
			
		||||
let config = JSON.parse(fs.readFileSync('config.json', 'utf8'))
 | 
			
		||||
let ws = new WebSocket(`ws://${config.servers.deconz.url}:${config.servers.deconz.websocketPort}`)
 | 
			
		||||
 | 
			
		||||
@@ -25,6 +26,14 @@ ws.on('message', msg => {
 | 
			
		||||
                }).catch(error => {
 | 
			
		||||
                    console.error(error)
 | 
			
		||||
                })
 | 
			
		||||
                if (device.openScript){
 | 
			
		||||
                    console.log("Running open script")
 | 
			
		||||
                    try {
 | 
			
		||||
                        console.log(exec.execSync(device.openScript).toString())
 | 
			
		||||
                    } catch (error) {
 | 
			
		||||
                        console.error(error)
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user