power source screen off

Post your questions and help other users.

Moderator: Martin

Post Reply
Ankit
Posts: 143
Joined: 11 Nov 2013 17:27

power source screen off

Post by Ankit » 05 Mar 2014 16:16

Hi
I am creating a flow which turn off screen when power source is plugged or unplugged. But the condition is that it should not turn off screen when display is already on.

But i am facing some problem.
Screen on condition is not working.
Please help...

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: power source screen off

Post by Martin » 05 Mar 2014 18:05

Hi,

Does the condition work when you open the condition and select Menu->Execute? The condition should show a notification on screen with the text Condition ended with 'True'.

Perhaps your device turns the screen on immediately when the power source is connected so the flow is executed too late and condition Screen On already evaluates to true.

In this case you would have to use a trigger Display State: On, store the time in a variable and check in the power connected/disconnected trigger whether the screen was turned on very recently.
Something like this:

Flow1
-trigger Display State: On
-action Script: global_last_screen_on_time = triggertime;

Flow2
-trigger Power Source: Connected
-action Sleep: 1s. Ensures that Flow1 had a chance to completely execute
-condition Expression: triggertime - global_screen_on_time < 2000. Checks if the screen was turned on within the last two seconds (2000ms).
-->true: -action Lock Device
-->false: -action Notification on Screen: Display was already turned on before

Regards,
Martin

Ankit
Posts: 143
Joined: 11 Nov 2013 17:27

Re: power source screen off

Post by Ankit » 06 Mar 2014 03:03

Hi martin

Thanx for your reply but my flow ended with an error..





6.03.2014 08:29:58.909 [Flow2] Starting to execute flow 'Flow2' with Context{global{global_battery_level=70,global_mode=Normal,global_screen=on,global_data=off,global_last_screen_on_time=1394074731770,global_tool=,global_turnoffscreen=off,global_free_ram=156,global_wifi=off},local{trigger='Power Source: Disconnected',battery_temperature=330,flow_name=Flow2,battery_level=71,battery_present=true,battery_technology=Li-ion,battery_scale=100,triggertime=1394074798890,battery_health=2,battery_status=3,battery_voltage=4077,battery_percentage=71.0,battery_plugged=0}}
06.03.2014 08:29:58.914 [Flow2] Start executing action 'Sleep: 1s (allow device sleep)'
06.03.2014 08:29:58.918 [Flow2] Action 'Sleep: 1s (allow device sleep)' Sleeping for 1s (allow device sleep)
06.03.2014 08:30:01.009 [Flow2] End executing action 'Sleep: 1s (allow device sleep)'
06.03.2014 08:30:01.131 [Flow2] Flow continues executing with the next step.
06.03.2014 08:30:01.132 [Flow2] Start executing condition 'Expression: triggertime -global_screen_on_time < 2000'
06.03.2014 08:30:01.225 [Flow2] Condition 'Expression: triggertime -global_screen_on_time < 2000'
ch.gridvision.ppam.androidautomagic.simplelang.a.c: can not apply operation - to values '1394074798890' and 'null'
at ch.gridvision.ppam.androidautomagic.simplelang.a.a.a(SourceFile:576)
at ch.gridvision.ppam.androidautomagic.simplelang.c.c.b(SourceFile:22)
at ch.gridvision.ppam.androidautomagic.simplelang.a.a.a(SourceFile:477)
at ch.gridvision.ppam.androidautomagic.simplelang.c.k.b(SourceFile:22)
at ch.gridvision.ppam.androidautomagic.simplelang.c.b.a(SourceFile:40)
at ch.gridvision.ppam.androidautomagic.simplelang.a.a.a(SourceFile:89)
at ch.gridvision.ppam.androidautomagic.simplelang.c.t.b(SourceFile:22)
at ch.gridvision.ppam.androidautomagic.simplelang.a.a.a(SourceFile:656)
at ch.gridvision.ppam.androidautomagic.simplelang.c.v.b(SourceFile:42)
at ch.gridvision.ppam.androidautomagic.simplelang.c.b.a(SourceFile:40)
at ch.gridvision.ppam.androidautomagic.simplelang.a.a.a(SourceFile:96)
at ch.gridvision.ppam.androidautomagic.simplelang.c.ai.b(SourceFile:33)
at ch.gridvision.ppam.androidautomagic.simplelang.a.h.a(SourceFile:693)
at ch.gridvision.ppam.androidautomagic.simplelang.a.h.a(SourceFile:669)
at ch.gridvision.ppam.androidautomagic.d.b.ab$1.c(SourceFile:131)
at ch.gridvision.ppam.androidautomagic.d.b.ab$1.a(SourceFile:120)
at ch.gridvision.ppam.androidautomagic.util.gc$1.run(SourceFile:39)
at java.lang.Thread.run(Thread.java:856)

06.03.2014 08:30:01.232 [Flow2] End executing condition 'Expression: triggertime -global_screen_on_time < 2000' with return value false and exception Could not execute expression 'triggertime -global_screen_on_time < 2000'
06.03.2014 08:30:01.312 [Flow2] Flow ends execution due to errors
06.03.2014 08:30:01.313 [Flow2] Error:
ch.gridvision.ppam.androidautomagic.util.n: Could not execute expression 'triggertime -global_screen_on_time < 2000'
at ch.gridvision.ppam.androidautomagic.d.b.ab$1.b(SourceFile:161)
at ch.gridvision.ppam.androidautomagic.util.gc$1$1.run(SourceFile:51)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
Caused by: ch.gridvision.ppam.androidautomagic.simplelang.a.c: can not apply operation - to values '1394074798890' and 'null'
at ch.gridvision.ppam.androidautomagic.simplelang.a.a.a(SourceFile:576)
at ch.gridvision.ppam.androidautomagic.simplelang.c.c.b(SourceFile:22)
at ch.gridvision.ppam.androidautomagic.simplelang.a.a.a(SourceFile:477)
at ch.gridvision.ppam.androidautomagic.simplelang.c.k.b(SourceFile:22)
at ch.gridvision.ppam.androidautomagic.simplelang.c.b.a(SourceFile:40)
at ch.gridvision.ppam.androidautomagic.simplelang.a.a.a(SourceFile:89)
at ch.gridvision.ppam.androidautomagic.simplelang.c.t.b(SourceFile:22)
at ch.gridvision.ppam.androidautomagic.simplelang.a.a.a(SourceFile:656)
at ch.gridvision.ppam.androidautomagic.simplelang.c.v.b(SourceFile:42)
at ch.gridvision.ppam.androidautomagic.simplelang.c.b.a(SourceFile:40)
at ch.gridvision.ppam.androidautomagic.simplelang.a.a.a(SourceFile:96)
at ch.gridvision.ppam.androidautomagic.simplelang.c.ai.b(SourceFile:33)
at ch.gridvision.ppam.androidautomagic.simplelang.a.h.a(SourceFile:693)
at ch.gridvision.ppam.androidautomagic.simplelang.a.h.a(SourceFile:669)
at ch.gridvision.ppam.androidautomagic.d.b.ab$1.c(SourceFile:131)
at ch.gridvision.ppam.androidautomagic.d.b.ab$1.a(SourceFile:120)
at ch.gridvision.ppam.androidautomagic.util.gc$1.run(SourceFile:39)
at java.lang.Thread.run(Thread.java:856)

06.03.2014 08:30:01.337 [Flow2] Flow ended.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: power source screen off

Post by Martin » 07 Mar 2014 07:50

Sorry, my mistake. The global variable in the second flow should have the same name as the one in the first flow.
Please change the condition in the second flow to:
-condition Expression: triggertime - global_last_screen_on_time < 2000

Ankit
Posts: 143
Joined: 11 Nov 2013 17:27

Re: power source screen off

Post by Ankit » 07 Mar 2014 11:21

Hi Martin

Thanx again for your reply but my flow again ended with an error.




07.03.2014 16:47:38.548 [Flow2] Starting to execute flow 'Flow2' with Context{global{global_battery_level=32,global_mode=Normal,global_screen=on,global_data=off,global_last_screen_on_time=1394190981802,global_tool=,global_turnoffscreen=off,global_free_ram=201,global_wifi=off,global_flashlight=off},local{trigger='Power Source: Disconnected',battery_temperature=320,flow_name=Flow2,battery_level=32,battery_present=true,battery_technology=Li-ion,battery_scale=100,triggertime=1394191058531,battery_health=2,battery_status=3,battery_voltage=3842,battery_percentage=32.0,battery_plugged=0}}
07.03.2014 16:47:38.572 [Flow2] Start executing action 'Sleep: 1s (allow device sleep)'
07.03.2014 16:47:38.573 [Flow2] Action 'Sleep: 1s (allow device sleep)' Sleeping for 1s (allow device sleep)
07.03.2014 16:47:40.688 [Flow2] End executing action 'Sleep: 1s (allow device sleep)'
07.03.2014 16:47:40.689 [Flow2] Flow continues executing with the next step.
07.03.2014 16:47:40.690 [Flow2] Start executing condition 'Expression: triggertime - global_ last_screen_on_time < 2000'
07.03.2014 16:47:40.700 [Flow2] Condition 'Expression: triggertime - global_ last_screen_on_time < 2000'
ch.gridvision.ppam.androidautomagic.simplelang.a.c: Could not evaluate expression 'triggertime - global_ last_screen_on_time < 2000' due to errors: [';' expected[22]]
at ch.gridvision.ppam.androidautomagic.simplelang.a.h.a(SourceFile:698)
at ch.gridvision.ppam.androidautomagic.simplelang.a.h.a(SourceFile:669)
at ch.gridvision.ppam.androidautomagic.d.b.ab$1.c(SourceFile:131)
at ch.gridvision.ppam.androidautomagic.d.b.ab$1.a(SourceFile:120)
at ch.gridvision.ppam.androidautomagic.util.gc$1.run(SourceFile:39)
at java.lang.Thread.run(Thread.java:856)

07.03.2014 16:47:40.703 [Flow2] End executing condition 'Expression: triggertime - global_ last_screen_on_time < 2000' with return value false and exception Could not execute expression 'triggertime - global_ last_screen_on_time < 2000'
07.03.2014 16:47:40.707 [Flow2] Flow ends execution due to errors
07.03.2014 16:47:40.721 [Flow2] Error:
ch.gridvision.ppam.androidautomagic.util.n: Could not execute expression 'triggertime - global_ last_screen_on_time < 2000'
at ch.gridvision.ppam.androidautomagic.d.b.ab$1.b(SourceFile:161)
at ch.gridvision.ppam.androidautomagic.util.gc$1$1.run(SourceFile:51)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
Caused by: ch.gridvision.ppam.androidautomagic.simplelang.a.c: Could not evaluate expression 'triggertime - global_ last_screen_on_time < 2000' due to errors: [';' expected[22]]
at ch.gridvision.ppam.androidautomagic.simplelang.a.h.a(SourceFile:698)
at ch.gridvision.ppam.androidautomagic.simplelang.a.h.a(SourceFile:669)
at ch.gridvision.ppam.androidautomagic.d.b.ab$1.c(SourceFile:131)
at ch.gridvision.ppam.androidautomagic.d.b.ab$1.a(SourceFile:120)
at ch.gridvision.ppam.androidautomagic.util.gc$1.run(SourceFile:39)
at java.lang.Thread.run(Thread.java:856)

07.03.2014 16:47:40.753 [Flow2] Flow ended.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: power source screen off

Post by Martin » 07 Mar 2014 13:44

It looks like there's a space in your variable name after the text global_. Please remove the space and try again.

Ankit
Posts: 143
Joined: 11 Nov 2013 17:27

Re: power source screen off

Post by Ankit » 07 Mar 2014 15:15

Thanx martin for your help and for your wonderful app!!

Post Reply