Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

toggle button - how to keep it showing the right state.

228 views
Skip to first unread message

fuzzywu...@gmail.com

unread,
Oct 21, 2024, 5:19:59 PM10/21/24
to Tasker
I have a scene with one of these and have noticed that if I destroy the scene and then reopen it:  the `toggle` state is not preserved.

Is there a way to make it so it remembers and so shows the previous state.

This is if I load the scene; toggle it; exit the scene then come back.
I want it to show the toggled  condition.

Possible?

Rich D

unread,
Oct 21, 2024, 7:14:10 PM10/21/24
to Tasker Google Groups Post

Possible?

Yes. You can do it with Element Depth. Use 2 toggle elements place one exactly over the other one. Tick the ON option in the first one.  In both "Changed" tab tasks  set the global variable %Toggle_scene TO: %new_val.  Then set up the show scene task like  so.. 





    Task: show test button
    
    A1: Flash [
         Text: %Toggle_scene
         Continue Task Immediately: On
         Dismiss On Click: On ]
    
    A2: Create Scene [
         Name: test button ]
    
    A3: Element Depth [
         Scene Name: test button
         Element: Toggle2
         Set Depth: 1 ]
        If  [ %Toggle_scene ~ on ]
    
    A4: Element Depth [
         Scene Name: test button
         Element: Toggle3
         Set Depth: 2 ]
    
    A5: Show Scene [
         Name: test button
         Display As: Overlay, Blocking
         Horizontal Position: 100
         Vertical Position: 100
         Animation: System
         Show Exit Button: On
         Show Over Keyguard: On
         Continue Task Immediately: On
         Allow Outside Boundaries: On
         Blocking Overlay +: On
         Overlay +: On ]
    
    A6: Wait [
         MS: 0
         Seconds: 10
         Minutes: 0
         Hours: 0
         Days: 0 ]
    
    A7: Destroy Scene [
         Name: test button ]
    
     

fuzzywu...@gmail.com

unread,
Oct 21, 2024, 8:25:49 PM10/21/24
to Tasker
Thanks.

(Not against you)
I'm not sure that is doing exactly what I meant, but....

That is going to take some time to understand.

I'm curious what this `element depth` is.
Though that is what you mentioned at the start of your reply.
I'll have to do some digging.
I'm an old fogie and am not good at handling this on my phone, so it isn't I can import it and see what it does.

fuzzywu...@gmail.com

unread,
Oct 21, 2024, 8:39:37 PM10/21/24
to Tasker
Which part of that do I need so I can import it to Tasker and see it running?
Do I need the Task: show test button line?
(And how do I import it in Tasker?)
(May be easier if I see a working version.)

Rich D

unread,
Oct 22, 2024, 5:29:00 AM10/22/24
to Tasker Google Groups Post

--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tasker/b1e5a4fa-5437-46c5-b6ec-d6391af70878n%40googlegroups.com.

fuzzywu...@gmail.com

unread,
Oct 22, 2024, 5:44:47 AM10/22/24
to Tasker
Thanks, but as I explained:  I don't have the phone......  in this loop  for getting to the forum.
So I am not sure how I am going to get to the link from my phone.
(Yeah, my problem, not yours.)

fuzzywu...@gmail.com

unread,
Oct 22, 2024, 5:53:15 AM10/22/24
to Tasker
I got it loaded - strangely.

Ok, error:

(This is painful)

gee the export is handy, but getting it from the phone to here is not fun.

Hang on and sorry for the pointless posts.
This stuff is really the wild west for me just now.

fuzzywu...@gmail.com

unread,
Oct 22, 2024, 5:55:54 AM10/22/24
to Tasker
Painfully ported to here.

The error:

20.53.20/LicenseCheckerTasker Checking cached only
20.53.20/LicenseCheckerTasker cache validity left -12017277178
20.53.20/LicenseCheckerTasker Cached status: Licensed
20.53.20/LicenseCheckerTasker Cached only: Licensed
20.53.20/TD getStatic: Active load: true - ExecuteService
20.53.20/Scene deepCopy: sticky toggle
20.53.20/SM createScene: already have scene named sticky toggle
20.53.20/E Create Scene: failed to create scene sticky toggle
20.53.20/E result: stop task (error)
20.53.20/E Error: 1
20.53.20/MacroEdit action finished exeID 1 action no 0 code 46 status: Err next 0

Ok, reading it, I can see/read that it is complaining  about the name and it already existing.
Believe me, I don't have one with that name.   Somehow it is/or seems to be tripping over itself.

So I guess I need to close that scene....????   But it isn't visible.

fuzzywu...@gmail.com

unread,
Oct 22, 2024, 6:00:51 AM10/22/24
to Tasker
Ok, update:

New error:

20.57.44/LicenseCheckerTasker Checking cached only
20.57.44/LicenseCheckerTasker cache validity left -12017541556
20.57.44/LicenseCheckerTasker Cached status: Licensed
20.57.44/LicenseCheckerTasker Cached only: Licensed
20.57.44/E Action requires accessibility but the accessibility service is disabled. Notification posted.
20.57.44/E result: stop task (error)
20.57.44/E Error: 1
20.57.44/MacroEdit action finished exeID 1 action no 3 code 47 status: Err next 3

Sorry.

Rich D

unread,
Oct 22, 2024, 6:01:05 AM10/22/24
to Tasker Google Groups Post
Yes.. I should have put a destroy scene action as the very first action in the task. 

You can manually run the destroy scene action from the task or..
 

If you open the scene for editing, that will destroy the task as well.

Rich D

unread,
Oct 22, 2024, 6:04:00 AM10/22/24
to Tasker Google Groups Post
In your Android settings under accessibility, you need to enable Tasker.. 

fuzzywu...@gmail.com

unread,
Oct 22, 2024, 6:05:22 AM10/22/24
to Tasker
I copy the `destroy scene` (from the last line) and put it at the start also.

Run.

Error.

Back to this one:
(with all the other stuff too)
Action requires accessibility but the accessibility service is disabled. Notification posted.

Confused.

I do - kind of - appreciate all the new security stuff on the new phones, but gee it can be painful too.

fuzzywu...@gmail.com

unread,
Oct 22, 2024, 6:09:25 AM10/22/24
to Tasker
This is weird.

I have OTHER scenes working.

AFAIK tasker is enabled.

When I follow the phone's offering for help I get a screen - yes:  ACCESSIBILITY, but ..... ..... confusion.


fuzzywu...@gmail.com

unread,
Oct 22, 2024, 6:12:12 AM10/22/24
to Tasker
Gee, that was fun.

(Not against you.)

Got it working.

Scene working.

I'll play with it and see what mess I can make.

THANKS!

fuzzywu...@gmail.com

unread,
Oct 22, 2024, 7:04:30 AM10/22/24
to Tasker
Wow, that is confusing.   (Not against you)

I copied the two lines from your code and pasted them in mine.
Then I had the fun of changing all the names.   That was fun.

I did one bit different.  Slightly I think.

On the TOGGLE thing on the CHANGE part:
(poor attempt to explain follows)
==============
IF  -------- %new_val ~ on
Default ringtone
Type ringer sound silent
notify title ringVolume
END IF

IF ---------- %new_val ~ off
Default rintone
Type ringer sound (my ringtone)
notify title ringVolume
END IF

Flash %new_val
Variable Set -- %ringMode to %new_val
==============

The %ringMode toggles if I press the button.
But if I exit the scene and come back it is not honoring  the value like yours does.

So I think I am missing something.

The code that makes the scene:
(again: poor effort)
======
Variable Set -- AltnotificationLevel to 4
(few more like this)
CreateScene ControlScene
Element Value Scene name Control Scene element Match  AutoReadName  to Value @AutoReadName
(and a couple more like this)
Then your two lines:
Element Depth ......
=============

Which - to me - is confusing.

The other ones that I did with `ELEMENT VALUE` work.

You are using `ELEMENT DEPTH`

No offense but I may try `ELEMENT VALUE`.

I'll let you know what happens.
Oh, that means I will only need one line of code.

fuzzywu...@gmail.com

unread,
Oct 22, 2024, 7:13:45 AM10/22/24
to Tasker
Oh, ok. Something else.

Your button name/s.....   Note the S.

You call your button, TOGGLE1

But in the ELEMENT DEPTH lines, there is/are TOGGLE1 and TOGGLE2.

Where is TOGGLE2 in the scheme of things?

I think that is where I got lost with your example.

Rich D

unread,
Oct 22, 2024, 7:08:24 PM10/22/24
to Tasker Google Groups Post

Your button name/s.....   Note the S.

You call your button, TOGGLE1

But in the ELEMENT DEPTH lines, there is/are TOGGLE1 and TOGGLE2.

Where is TOGGLE2 in the scheme of things?

Just to clarify..These are not button elements, they are Toggle Elements.

There are actually 2 Toggle elements. 

The Toggle2 element is hidden under the Toggle1 element.  They are the exact same size and placed on top of one another.  So which one is shown depends on the depth setting.  


So Toggle1 does not have the "ON' option set and Togggle2 does have the "ON" option set.  So the Global variable determines which Element is set to a depth of 1 which hides that particular element behind the other. 

fuzzywu...@gmail.com

unread,
Oct 23, 2024, 1:47:48 AM10/23/24
to Tasker
So if my `toggle` element is called RingMode I transposed your Toggle1 to RingMode, but was not sure what to call Toggle1's transposed name.

RingMode1 or 2?
And I'm sorry I said BUTTON and not TOGGLE.  My fault.

But I seem to lack the ability to completely reuse your code so I can make multiple instances of it.

Is that clearer?

Rich D

unread,
Oct 23, 2024, 4:58:29 AM10/23/24
to Tasker Google Groups Post

So if my `toggle` element is called RingMode I transposed your Toggle1 to RingMode, but was not sure what to call Toggle1's transposed name.

RingMode1 or 2?

You would need 2 Toggle elements called RingMode1  and Ringtone2.

You can link them to the same task in the "Change"  Tab within the Elements UI Edit mode. To do that you need to name that task.  To Name that Task you Select all your current actions in the task and tap "Copy" then in the upper right Tap the  - "Select Different Task"

Then at the top of that Menu there is a "New" option. Select that and name your task. Then long press the middle of the screen and Paste your actions into it. 

Then in the Ringtone2 you can now select that task as well. 

I have changed the project with your new names and a linked task for the Toggle elements. I also moved one of the elements to better show that there are 2 Toggle elements in this task. You can move one on top of the other so they will show as one just like the first version.

Try importing this again..


 Do use the APP 'Telegram'?   I have found that a much better way to with these back and forths to explain and show show examples. 

aa6vh

unread,
Oct 24, 2024, 10:20:34 AM10/24/24
to Tasker
I think you all are making this a lot harder than it needs to be.

Create a Tasker Global variable to store that element between the showing of the scene. In your "load Scene" task, set the element to the value of that Global Variable, using the "Element Text" or "Element Value" actions. In the scene, whenever that element is updated, save the updated value back into that Global.

Rich D

unread,
Oct 24, 2024, 4:17:14 PM10/24/24
to Tasker Google Groups Post
Well that's strange...  I know for certain I tested the Element Value action before replying..  

I tested with both one and zero and for some reason it did not work. 

The documents do not seem to list The toggle Element in Element value action., so I assumed it did not work. 😞 

After testing again, it does indeed work for setting the toggle element.. 

A value of one will turn it off and a value of zero will turn it on.

Thanks for the correction.... :)

fuzzywu...@gmail.com

unread,
Oct 25, 2024, 3:44:52 AM10/25/24
to Tasker
Rich D,

Your code works.  No problem.

But I can't see how/where you have the second button.
Although you explained it a couple of posts ago, I am still not understanding.   (My fault)

aa6vh,
Maybe I am making it harder than it needs.

But as I don't know the way to do it, I am trying to understand the workings.

I (stupidly) didn't realise the names and the associations on the SCENE and the TOGGLE.   But after a slap in the face a few times I saw it.
Alas that opened the can of worms where/how the second button is done.

I'll see if I can get what you suggested to work.

fuzzywu...@gmail.com

unread,
Oct 25, 2024, 3:51:41 AM10/25/24
to Tasker
(Sorry, all)

One TWIST  is the values and the text are very different.

The text shows the mode  and the value is the ring tone.

I'm not sure if I could save the mode to the global variable and have an external bit of code that then parses it for changes.

Again:  I don't often do this as I am buried in programming in other languages.

Rich D

unread,
Oct 26, 2024, 6:24:47 AM10/26/24
to Tasker Google Groups Post

Are you using the Element Value action  (Recommend) or are you still using the Element Depth method?


One TWIST  is the values and the text are very different.

The text shows the mode  and the value is the ring tone

Can you give more details?  What do you mean "value is the ring tone" ? 

aa6vh

unread,
Oct 26, 2024, 11:06:50 AM10/26/24
to Tasker
Remember guys, the "Element Text" action and the "Element Value" action do the same thing, but for different targets. Take a look at the Tasker Help for those actions.

"Element Text" is for Button, Text, and Edit elements only. "Element Value" is for Checkbox, Number, Picker, Slider., Spinner, and Toggle elements.

fuzzywu...@gmail.com

unread,
Oct 26, 2024, 11:47:04 PM10/26/24
to Tasker
The BUTTON (to call it) has the alternate text/s:  NORMAL and CONTACTS ONLY.
But it sets the phone's DEFAULT RINGTONE.
So it toggles that between CAR_HORN and SILENT.

So, normally when an unknown/non-contact calls me the CAR_HORN is the RINGTONE.
People who I know have a different one.

This will enable me to have the phone so if an unlisted number calls, the phone doesn't ring.
But if a contact calls, the phone works normally.

fuzzywu...@gmail.com

unread,
Oct 26, 2024, 11:58:54 PM10/26/24
to Tasker
> Remember guys, the "Element Text" action and the "Element Value" action do the same thing, but for different targets. Take a look at the Tasker Help for those actions.
>"Element Text" is for Button, Text, and Edit elements only. "Element Value" is for Checkbox, Number, Picker, Slider., Spinner, and Toggle elements.

Yes, and so I have a lot of lines in the code - now - turned OFF (they don't work and I'm anal).
I added a line:  ELEMENT TEXT
Scene:  ControlScene
Element: RingMode
Text: ringText

Pressed the button to apply.

Some error - sorry, I dismissed it too quickly.

THIS CAN'T BE DONE WITH THE TOGGLE OPTION....
Or words to that end.

So, sorry, how am I supposed to control the text shown on a TOGGLE button?

Please forgive the CAPS stuff....    Formatting here is painful and I don't know of an easy  way to identify the key parts/words so I capitalise them.

fuzzywu...@gmail.com

unread,
Oct 27, 2024, 12:02:32 AM10/27/24
to Tasker
If I wanted to post the CODE (now sure what to call it) on the phone, do I export it as:
XML to Clipboard
Description to Clipboard

and then paste it here?

(BTW, which ever way, it is going to be kinda painful for me)

Rich D

unread,
Oct 27, 2024, 8:42:43 AM10/27/24
to Tasker Google Groups Post

The BUTTON (to call it) has the alternate text/s:  NORMAL and CONTACTS ONLY.
But it sets the phone's DEFAULT RINGTONE.
So it toggles that between CAR_HORN and SILENT.

So, normally when an unknown/non-contact calls me the CAR_HORN is the RINGTONE.
People who I know have a different one.


Ok,  I believe I understand the issue.   Here is a updated link for what I believe you are looking for. 

Download this one and see if it works for you.  You will need to edit the Task > "Toggle Ringtone"  . Edit the "Default Ringtone"  actions to set them for your needs. 





    Project: sticky toggle Scene
    
    
    
    Tasks
        Task: show sticky toggle
        
        A1: Create Scene [
             Name: sticky toggle ]
        
        A2: Flash [
             Text: %Toggle_scene
             Dismiss On Click: On ]
        
        A3: Element Value [
             Scene Name: sticky toggle
             Element Match: Toggle1
             Value: 1 ]
            If  [ %Toggle_scene ~ on ]
        
        A4: Element Value [
             Scene Name: sticky toggle
             Element Match: Toggle1
             Value: 0 ]
            If  [ %Toggle_scene ~ off ]
        
        A5: Show Scene [
             Name: sticky toggle
             Display As: Overlay, Blocking
             Horizontal Position: 100
             Vertical Position: 100
             Animation: System
             Show Exit Button: On
             Show Over Keyguard: On
             Continue Task Immediately: On
             Allow Outside Boundaries: On
             Blocking Overlay +: On
             Overlay +: On ]
        
        A6: Wait [
             MS: 0
             Seconds: 15
             Minutes: 0
             Hours: 0
             Days: 0 ]
        
        A7: Destroy Scene [
             Name: sticky toggle ]
        
        
    
        Task: Toggle Ringtone
        Settings: Abort Existing Task
        
        A1: Variable Set [
             Name: %Toggle_scene
             To: %new_val
             Structure Output (JSON, etc): On ]
        
        A2: If [ %new_val ~ on ]
        
            A3: Flash [
                 Text: Set to CAR_HORN
                 Long: On
                 Tasker Layout: On
                 Continue Task Immediately: On
                 Dismiss On Click: On ]
        
            A4: Default Ringtone [
                 Type: Ringer
                 Sound: Silent ]
        
        A5: End If
        
        A6: If [ %new_val ~ off ]
        
            A7: Flash [
                 Text: Set to SILENT
                 Long: On
                 Tasker Layout: On
                 Continue Task Immediately: On
                 Dismiss On Click: On ]
        
            A8: Default Ringtone [
                 Type: Ringer
                 Sound: Silent ]
        
        A9: End If
        
        





aa6vh

unread,
Oct 27, 2024, 10:55:55 AM10/27/24
to Tasker
Now I have a better understanding of what you are trying to do.  And yes, there is no direct way in Tasker to effect the label of a toggle.

So what I do is make the toggle label blank, then place a label object next to that toggle (so that the new label is now appears to be the toggle's label), and just adjust that label.

fuzzywu...@gmail.com

unread,
Oct 27, 2024, 3:38:26 PM10/27/24
to Tasker
Thanks.

Just mentioning....

The code:   Toggle_Ringtone part 4.

That should be:
Sound: Car_Horn]

Yes?

NO big deal.  Ooops moment.

Shall try shortly.

fuzzywu...@gmail.com

unread,
Oct 27, 2024, 3:39:29 PM10/27/24
to Tasker
(ARGH)   Can't edit.

Ok I made a mistake there too..

Sound: CAR_HORN]

Yeah?

fuzzywu...@gmail.com

unread,
Oct 27, 2024, 3:42:11 PM10/27/24
to Tasker
(Argh again)

And......

Won't I need a global variable as it needs to survive the scene being closed/destroyed?

This was mentioned by aa6vh a few posts back.

Rich D

unread,
Oct 27, 2024, 10:16:23 PM10/27/24
to Tasker Google Groups Post

And......

Won't I need a global variable as it needs to survive the scene being closed/destroyed?

There is a global variable. 

%Toggle_scene

We're you able to set the Ringtone actions to the correct sound settings?


Can you describe what is not working?

fuzzywu...@gmail.com

unread,
Oct 28, 2024, 1:08:12 AM10/28/24
to Tasker
Sorry Rich D.

My mistake.

Not yet.  Today has been busy for me and I am now trying to catch up on things.
My comments/posts were just from reading the code (text) you posted.

I'll get back to you with the results once I try it.

I am just ........ not sure it will help me if it is like the first one as I could not see how you got the Toggle2 part.

Though you did reply and did say what you did......   This end, it was not really something I could understand.
My problem, I know.

fuzzywu...@gmail.com

unread,
Oct 28, 2024, 1:17:58 AM10/28/24
to Tasker
Ok, imported it and it seems to work.

Question:
When I run it, why does it take so long to display the scene?  It is like 3 seconds.

I get the FLASH message and it just sits there.   The scene does come up but .......

Anyway:  Good, it works.

Next PROBLEM  is that this is going to be difficult for me to read through and get the jist of to then duplicate it in my other ..... TASK  ?

And....  (you're going to love this)   I actually need this code as I need TWO of that kind of thing.  (The TOGGLE and changing things.)

The second one will put the phone into full SILENT mode.

fuzzywu...@gmail.com

unread,
Oct 28, 2024, 1:22:26 AM10/28/24
to Tasker
AARRGGHH!!

Silly me....   That point I mentioned about the ringtone being set to SILENT.....

The code has that and so no matter what the button says, the phone ringtone is set to SILENT.

No big.   I can change that.

fuzzywu...@gmail.com

unread,
Oct 28, 2024, 1:35:03 AM10/28/24
to Tasker
Where does TOGGLE RINGTONE get ..... invoked  ?
It is a separate task and they usually are called by a PROFILE.

Rich D

unread,
Oct 28, 2024, 4:40:51 AM10/28/24