What version are you on? I can’t do much if you don’t share a piston.
This one here works:
7/22/2017, 3:44:05 PM +676ms
+1ms ╔Received event [Home].powerSource = battery with a delay of 111ms
+453ms ║RunTime Analysis CS > 45ms > PS > 363ms > PE > 45ms > CE
+460ms ║Piston waited at a semaphore for 277ms
+464ms ║Runtime (35769 bytes) successfully initialized in 363ms (v0.2.0dc.20170722) (462ms)
+466ms ║╔Execution stage started
+482ms ║║Comparison battery changes_to battery = false (1ms)
+485ms ║║Cancelling condition #4's schedules...
+487ms ║║Condition #4 evaluated false (9ms)
+488ms ║║Cancelling condition #1's schedules...
+490ms ║║Condition group #1 evaluated false (state changed) (13ms)
+495ms ║╚Execution stage complete. (30ms)
+505ms ╚Event processed successfully (505ms)
7/22/2017, 3:44:05 PM +627ms
+1ms ╔Received event [Home].powerSource = battery with a delay of 65ms
+151ms ║RunTime Analysis CS > 53ms > PS > 65ms > PE > 32ms > CE
+159ms ║Runtime (35678 bytes) successfully initialized in 65ms (v0.2.0dc.20170722) (157ms)
+161ms ║╔Execution stage started
+177ms ║║Comparison battery changes_to battery = true (2ms)
+180ms ║║Cancelling condition #4's schedules...
+181ms ║║Condition #4 evaluated true (9ms)
+183ms ║║Cancelling condition #1's schedules...
+184ms ║║Condition group #1 evaluated true (state changed) (13ms)
+189ms ║║Cancelling statement #2's schedules...
+211ms ║║Executed virtual command log (10ms)
+216ms ║╚Execution stage complete. (56ms)
+224ms ╚Event processed successfully (223ms)
LATER EDIT: Looks like those events are not very reliable - I never got a power=mains event (checking the IDE) and then no more events were sent for subsequent battery/mains flips. I need to find another solution for this.