Setup switch case with window contacts


#1

1) Give a description of the problem
I have a few window contacts, that I want to change the radiator heat level.

2) What is the expected behaviour?
I would like to have so that when a certain window opens a specific thermostat changes value. f.x. shuts off and when the window i closed again it turn on to a predefined heat level.

I have the heating level working in another script using a lot of if sentences. So I wanted to minimize code using CASE.

3) What is happening/not happening?
I am not certain on how to make it work correctly. I can make the code send me a PUSH msg when opening the “kontor” window but when trying the second CASE (Terrassedør) it sends a message from “Vindue kontor”. I somehow does not match the CASE.

4) Post a Green Snapshot of the pistonimage

5) Attach logs after turning logging level to Full
╔Received event [Terrassedør stue].contact = closed with a delay of 42ms
+33ms ║RunTime Analysis CS > 12ms > PS > 4ms > PE > 17ms > CE
+35ms ║Runtime (40829 bytes) successfully initialized in 4ms (v0.3.113.20210203) (34ms)
+36ms ║╔Execution stage started
+160ms ║║Evaluating switch with values [i::b97623c7fcb8f38dc70981fe6a1de680::contact, v:[t:enum, v:closed, d::b97623c7fcb8f38dc70981fe6a1de680:, a:contact, i:null, x:false, vt:string]], [i::98a2facbeb7efb8ca36f27e6f4b7237a::contact, v:[t:enum, v:closed, d::98a2facbeb7efb8ca36f27e6f4b7237a:, a:contact, i:null, x:false, vt:string]], [i::a13c35817f4c5febe22fd0066208cac6::contact, v:[t:enum, v:open, d::a13c35817f4c5febe22fd0066208cac6:, a:contact, i:null, x:false, vt:string]], [i::ce17814dfbee435ce760850d194d5549::contact, v:[t:enum, v:closed, d::ce17814dfbee435ce760850d194d5549:, a:contact, i:null, x:false, vt:string]], [i::5e2fc5c890dccf6483b2dcd0aca8f174::contact, v:[t:enum, v:closed, d::5e2fc5c890dccf6483b2dcd0aca8f174:, a:contact, i:null, x:false, vt:string]], [i::c0072808e0ff9461b97eb2281ba906e1::contact, v:[t:enum, v:open, d::c0072808e0ff9461b97eb2281ba906e1:, a:contact, i:null, x:false, vt:string]], i::2b8f4c949a31f33081d27449fcf7e1af::contact, v:t:enum, v:closed, d::2b8f4c949a31f33081d27449fcf7e1af:, a:contact…[TRUNCATED]
+166ms ║║Comparison (enum) closed is (enum) closed = true (2ms)
+176ms ║║Comparison (enum) closed is (string) closed = true (2ms)
+178ms ║║Condition #4 evaluated true (10ms)
+180ms ║║Condition group #3 evaluated true (state did not change) (12ms)
+182ms ║║Cancelling statement #7’s schedules…
+196ms ║║Executed virtual command sendPushNotification (8ms)
+201ms ║╚Execution stage complete. (164ms)
+202ms ╚Event processed successfully (202ms)
19.9.2021 18.29.23 +498ms
+1ms ╔Received event [Terrassedør stue].contact = open with a delay of 65ms
+41ms ║RunTime Analysis CS > 17ms > PS > 5ms > PE > 20ms > CE
+44ms ║Runtime (40829 bytes) successfully initialized in 5ms (v0.3.113.20210203) (42ms)
+45ms ║╔Execution stage started
+79ms ║║Evaluating switch with values [i::b97623c7fcb8f38dc70981fe6a1de680::contact, v:[t:enum, v:closed, d::b97623c7fcb8f38dc70981fe6a1de680:, a:contact, i:null, x:false, vt:string]], [i::98a2facbeb7efb8ca36f27e6f4b7237a::contact, v:[t:enum, v:open, d::98a2facbeb7efb8ca36f27e6f4b7237a:, a:contact, i:null, x:false, vt:string]], [i::a13c35817f4c5febe22fd0066208cac6::contact, v:[t:enum, v:open, d::a13c35817f4c5febe22fd0066208cac6:, a:contact, i:null, x:false, vt:string]], [i::ce17814dfbee435ce760850d194d5549::contact, v:[t:enum, v:closed, d::ce17814dfbee435ce760850d194d5549:, a:contact, i:null, x:false, vt:string]], [i::5e2fc5c890dccf6483b2dcd0aca8f174::contact, v:[t:enum, v:closed, d::5e2fc5c890dccf6483b2dcd0aca8f174:, a:contact, i:null, x:false, vt:string]], [i::c0072808e0ff9461b97eb2281ba906e1::contact, v:[t:enum, v:open, d::c0072808e0ff9461b97eb2281ba906e1:, a:contact, i:null, x:false, vt:string]], i::2b8f4c949a31f33081d27449fcf7e1af::contact, v:t:enum, v:closed, d::2b8f4c949a31f33081d27449fcf7e1af:, a:contact, …[TRUNCATED]
+86ms ║║Comparison (enum) closed is (enum) closed = true (2ms)
+95ms ║║Comparison (enum) closed is (string) closed = true (2ms)
+97ms ║║Condition #4 evaluated true (9ms)
+98ms ║║Condition group #3 evaluated true (state did not change) (10ms)
+101ms ║║Cancelling statement #7’s schedules…
+127ms ║║Executed virtual command sendPushNotification (21ms)
+130ms ║╚Execution stage complete. (85ms)
+131ms ╚Event processed successfully (131ms)
19.9.2021 18.28.40 +223ms
+1ms ╔Received event [Vindue kontor].contact = closed with a delay of 81ms
+59ms ║RunTime Analysis CS > 18ms > PS > 6ms > PE > 36ms > CE
+62ms ║Runtime (40826 bytes) successfully initialized in 6ms (v0.3.113.20210203) (60ms)
+63ms ║╔Execution stage started
+96ms ║║Evaluating switch with values [i::b97623c7fcb8f38dc70981fe6a1de680::contact, v:[t:enum, v:closed, d::b97623c7fcb8f38dc70981fe6a1de680:, a:contact, i:null, x:false, vt:string]], [i::98a2facbeb7efb8ca36f27e6f4b7237a::contact, v:[t:enum, v:closed, d::98a2facbeb7efb8ca36f27e6f4b7237a:, a:contact, i:null, x:false, vt:string]], [i::a13c35817f4c5febe22fd0066208cac6::contact, v:[t:enum, v:open, d::a13c35817f4c5febe22fd0066208cac6:, a:contact, i:null, x:false, vt:string]], [i::ce17814dfbee435ce760850d194d5549::contact, v:[t:enum, v:closed, d::ce17814dfbee435ce760850d194d5549:, a:contact, i:null, x:false, vt:string]], [i::5e2fc5c890dccf6483b2dcd0aca8f174::contact, v:[t:enum, v:closed, d::5e2fc5c890dccf6483b2dcd0aca8f174:, a:contact, i:null, x:false, vt:string]], [i::c0072808e0ff9461b97eb2281ba906e1::contact, v:[t:enum, v:open, d::c0072808e0ff9461b97eb2281ba906e1:, a:contact, i:null, x:false, vt:string]], i::2b8f4c949a31f33081d27449fcf7e1af::contact, v:t:enum, v:closed, d::2b8f4c949a31f33081d27449fcf7e1af:, a:contact…[TRUNCATED]
+101ms ║║Comparison (enum) closed is (enum) closed = true (1ms)
+108ms ║║Comparison (enum) closed is (string) closed = true (2ms)
+110ms ║║Cancelling condition #4’s schedules…
+111ms ║║Condition #4 evaluated true (8ms)
+113ms ║║Cancelling condition #3’s schedules…
+114ms ║║Condition group #3 evaluated true (state changed) (11ms)
+117ms ║║Cancelling statement #7’s schedules…
+135ms ║║Executed virtual command sendPushNotification (11ms)
+138ms ║╚Execution stage complete. (75ms)
+140ms ╚Event processed successfully (140ms)
19.9.2021 18.28.33 +631ms
+1ms ╔Received event [Vindue kontor].contact = open with a delay of 46ms
+32ms ║RunTime Analysis CS > 12ms > PS > 4ms > PE > 15ms > CE
+34ms ║Runtime (40826 bytes) successfully initialized in 4ms (v0.3.113.20210203) (32ms)
+35ms ║╔Execution stage started
+89ms ║║Evaluating switch with values [i::b97623c7fcb8f38dc70981fe6a1de680::contact, v:[t:enum, v:closed, d::b97623c7fcb8f38dc70981fe6a1de680:, a:contact, i:null, x:false, vt:string]], [i::98a2facbeb7efb8ca36f27e6f4b7237a::contact, v:[t:enum, v:closed, d::98a2facbeb7efb8ca36f27e6f4b7237a:, a:contact, i:null, x:false, vt:string]], [i::a13c35817f4c5febe22fd0066208cac6::contact, v:[t:enum, v:open, d::a13c35817f4c5febe22fd0066208cac6:, a:contact, i:null, x:false, vt:string]], [i::ce17814dfbee435ce760850d194d5549::contact, v:[t:enum, v:closed, d::ce17814dfbee435ce760850d194d5549:, a:contact, i:null, x:false, vt:string]], [i::5e2fc5c890dccf6483b2dcd0aca8f174::contact, v:[t:enum, v:open, d::5e2fc5c890dccf6483b2dcd0aca8f174:, a:contact, i:null, x:false, vt:string]], [i::c0072808e0ff9461b97eb2281ba906e1::contact, v:[t:enum, v:open, d::c0072808e0ff9461b97eb2281ba906e1:, a:contact, i:null, x:false, vt:string]], i::2b8f4c949a31f33081d27449fcf7e1af::contact, v:t:enum, v:closed, d::2b8f4c949a31f33081d27449fcf7e1af:, a:contact, …[TRUNCATED]
+93ms ║║Comparison (enum) closed is (enum) open = false (1ms)
+95ms ║║Comparison (enum) closed is (enum) open = false (1ms)
+98ms ║║Comparison (enum) open is (enum) open = true (1ms)
+104ms ║║Comparison (enum) open is (string) closed = false (1ms)
+106ms ║║Cancelling condition #4’s schedules…
+107ms ║║Condition #4 evaluated false (7ms)
+109ms ║║Cancelling condition #3’s schedules…
+110ms ║║Condition group #3 evaluated false (state changed) (9ms)
+112ms ║║Cancelling statement #20’s schedules…
+125ms ║║Executed virtual command sendPushNotification (8ms)
+202ms ║╚Execution stage complete. (167ms)
+204ms ╚Event processed successfully (203ms)

REMOVE BELOW AFTER READING


#2

OK I am not entirely sure how the switch statement will evaluate, but ‘probably not how you want it to’ is likely to be enough. I would try something like:

if
  Any of (your list of devices) contact changes
then
  switch( $currentEventDevice )
      case Vindue kontor:
           (your existing code)
      case Terrassedor stue:
           (your existing code)
  end switch
end if

If you look at the logs you will see there are lines such as:

Received event [Terrassedør stue].contact = open

That tells you that the piston received an event to say the device Terrassedør stue's contact attribute is open. This information is available to the piston as the device variable $currentEventDevice, the $currentEventAttribute, and the $currentEventValue.

The trigger condition in the if will make the piston run every time it has received a contact event from a device in the list and return true if one of the device attributes has actually changed (i.e. open -> closed, or closed -> open).

You can then call the switch statement with the $currentEventDevice. That has the ‘Device’ type so in the case statements you can just pick a device from the list the editor offers.

The content of your case blocks should then be OK.

As things stand you could actually replace the entire switch block with the notification “$currentEventDevice is $currentEventValue” but I noted you had more to add to the case blocks.


#3

Works like a charm :slight_smile: