Members mschaeffler Posted December 6, 2023 Members Posted December 6, 2023 // Konstanten let maxCyclic = 60 * 4; let maxState = { "-": 0, "S": 90*4, "D": 5*60*4, "L": 60*60*4, "w": 1, "W": 12 }; // globale Variablen let switchoffTimer = null; let state = Shelly.getComponentStatus( "enum", 200 ).value; let cntState = 0; let cntCyclic = 0; let mqttPrefix = Shelly.getComponentConfig( "mqtt" ).topic_prefix; function showState() { MQTT.publish( mqttPrefix+"/status/enum:200", "{\"value\":\""+state+"\"}", 1, false ); } function setState(aState) { state = aState; cntState = maxState[aState]; showState(); } function checkState() { if( state !== "-" ) { cntState = cntState - 1; if( cntState <= 0 ) { if( state === "S" || state === "D" || state === "L" ) { switchWarn1(); } else if( state === "w" ) { switchWarn2(); } else { Shelly.call( "Enum.Set", { id:200, value:"-" }, null, null ); } } } } function switchOff() { print( "Output switched off" ); Shelly.call( "Switch.Set", { id:0, on:false }, null, null ); setState( "-" ); } function switchOn(aState) { print( "Output switched on ", aState ); Shelly.call( "Switch.Set", { id:0, on:true }, null, null ); setState( aState ); } function switchWarn1() { print( "Output switched warn 1" ); Shelly.call( "Switch.Set", { id:0, on:false }, null, null ); setState( "w" ); } function switchWarn2() { print( "Output switched warn 2" ); Shelly.call( "Switch.Set", { id:0, on:true }, null, null ); setState( "W" ); } function shortPress() { print( "short press" ); if( state !== "L" ) { switchOn( "S" ); } } function doublePress() { print( "double press" ); if( state !== "L" ) { switchOn( "D" ); } } function longPress() { print( "long press" ); if( state !== "L" ) { switchOn( "L" ); } else { Shelly.call( "Enum.Set", { id:200, value:"-" }, null, null ); } } // Handler Shelly.addEventHandler( function(event,ud) { //print( JSON.stringify(event) ); if( event.name === 'input' && event.id === 0 ) { print( "Input event", event.id ); if( event.info.event === "single_push" ) { Shelly.call( "Enum.Set", { id:200, value:"S" }, null, null ); } else if( event.info.event === "double_push" ) { Shelly.call( "Enum.Set", { id:200, value:"D" }, null, null ); } else if( event.info.event === "long_push" ) { Shelly.call( "Enum.Set", { id:200, value:"L" }, null, null ); } } }, null ); Shelly.addStatusHandler( function(event,ud) { //print( JSON.stringify(event) ); if( event.component === "enum:200" ) { print(event.delta.value); if( event.delta.value === "S" ) { shortPress(); } else if( event.delta.value === "D" ) { doublePress(); } else if( event.delta.value === "L" ) { longPress(); } else if( event.delta.value === "-" ) { switchOff(); } } }, null ); // Main if( state !== "-" ) { Shelly.call( "Enum.Set", { id:200, value:"-" }, null, null ); } else { showState(); } Timer.set( 250, true, function(ud) { if( ++cntCyclic >= maxCyclic ) { cntCyclic = 0; showState(); } checkState(); }, null ); Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish
Dimitar Posted December 6, 2023 Posted December 6, 2023 Can you explain 🙂 what you control with this script. Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish
Members mschaeffler Posted December 7, 2023 Author Members Posted December 7, 2023 the main idea is this: a short press on the button or sending "S" to the enum starts a 4min timer and then a warning (short off and some additional time on) two pressed or "D" a longer timer and long press or "L" light for one hour. I have a similar script running on two gen2 devices and just changed the communication to the control system in a RPC style with the virtual enum. Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish
Shelly Lyubomir Petrov Posted December 8, 2023 Shelly Posted December 8, 2023 Weird, our QAs couldn't replicate it. What version of the firmware are you running? Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish
Members mschaeffler Posted December 8, 2023 Author Members Posted December 8, 2023 (edited) 8 hours ago, Lyubomir Petrov said: Weird, our QAs couldn't replicate it. What version of the firmware are you running? Edited December 8, 2023 by mschaeffler Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish
Shelly Lyubomir Petrov Posted December 11, 2023 Shelly Posted December 11, 2023 On 12/8/2023 at 6:42 PM, mschaeffler said: Image doesn't open :? Quote Translate Revert translation? English (American) Finnish French German Italian Portuguese (European) Spanish
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.