metadata { definition(name: "Cenas Switch IR Tuya", namespace: "jorgespneto", author: "Jorge Palmeira") { capability "Switch" } } preferences { input name: "TasmotaIP", title:"local IP address of Tasmota IR", type: "string", required: true input name: "username", title:"Username of Tasmota IR", type: "string" input name: "password", title:"Password of Tasmota IR", type: "string" input name: "OnIRsend", title:"On - Código IR", type: "string" input name: "OnIRsend2", title:"On - Código IR2", type: "string" input name: "OnIRsend3", title:"On - Código IR3", type: "string" input name: "OnIRsend4", title:"On - Código IR4", type: "string" input name: "OnIRsend5", title:"On - Código IR5", type: "string" input name: "OnIRsend6", title:"On - Código IR6", type: "string" input name: "OffIRsend", title:"Off - Código IR", type: "string" input name: "offThreshold", title:"Off Threshold Power (W)", type: "number", required: true, defaultValue: 3.9 input name: "onThreshold", title:"On Threshold Power (W)", type: "number", required: true, defaultValue: 4 } def parse(String description) { log.debug description } def installed() { initialize() } def updated() { initialize() } def initialize() { } //def on() { // sendTasmota('IRsend '+ONIR) //sendEvent(name: "switch", value: "on") //pause(2000) //sendTasmota('IRsend '+ONIR2) //pause(2000) //sendTasmota('IRsend '+ONIR3) //pause(2000) //sendTasmota('IRsend '+ONIR4) //pause(2000) //sendTasmota('IRsend '+ONIR5) //pause(2000) //sendTasmota('IRsend '+ONIR6) //pause(2000) //sendEvent(name: "switch", value: "off") //} def on() { sendTasmota('IRsend '+ONIR) sendEvent(name: "switch", value: "on") runIn(2,'cena2') runIn(4,'cena3') runIn(6,'cena4') runIn(8,'cena5') runIn(10,'cena6') runIn(12,'autoturnoff') } def cena2() { sendTasmota('IRsend '+ONIR2) log.Info sending cena2 } def cena3() { sendTasmota('IRsend '+ONIR3) log.Info sending cena3 } def cena4() { sendTasmota('IRsend '+ONIR4) log.Info sending cena4 } def cena5() { sendTasmota('IRsend '+ONIR5) log.Info sending cena5 } def cena6() { sendTasmota('IRsend '+ONIR6) log.Info sending cena5 } def autoturnoff() { sendEvent(name: "switch", value: "off") log.Info sending autoturnoff } def off() { sendTasmota('IRsend '+OFFIR) sendEvent(name: "switch", value: "off") } def sendTasmota(command) { def options = [ method: "GET", headers: [HOST: settings.TasmotaIP+":80"], path: "/cm?user=" + (settings.username ?: "") + "&password=" + (settings.password ?: "") + "&cmnd=" + URLEncoder.encode(command, "UTF-8").replaceAll(/\+/,'%20') ] log.debug options def hubAction = new hubitat.device.HubAction(options, null) //Alterei sendHubCommand(hubAction) } def getONIR() { return (settings.OnIRsend ?: "") } def getONIR2() { return (settings.OnIRsend2 ?: "") } def getONIR3() { return (settings.OnIRsend3 ?: "") } def getONIR4() { return (settings.OnIRsend4 ?: "") } def getONIR5() { return (settings.OnIRsend5 ?: "") } def getONIR6() { return (settings.OnIRsend6 ?: "") } def getOFFIR() { return (settings.OffIRsend ?: "") }