๐ŸŽ„โ›„โ„๏ธ๐ŸŽ It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! ๐ŸŽ„โ›„โ„๏ธ๐ŸŽ
0

Update Dashboard Toggle Switch from device
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Update Dashboard Toggle Switch from device

by phdsplanning on Mon Oct 21, 2019 9:44 am

I have a device that has a feature controlled both a local hardware button on the device, and a toggle switch on the IO dashboard. When a user presses the the local hardware button, I would like to push the state change up to the IO Dashboard to reflect the change. Pulling the status from the Dashboard toggle is working fine per the user guide. Is pushing the toggle switch state back to the dashboard supported?

I am using the python Adafruit_IO library on a Beaglebone blue.

Thanks!

phdsplanning
 
Posts: 2
Joined: Mon Oct 21, 2019 9:28 am

Re: Update Dashboard Toggle Switch from device

by brubell on Mon Oct 21, 2019 10:33 am

Hi phdsplanning,

Is pushing the toggle switch state back to the dashboard supported?


Yes, this is supported. The toggle switch block is tied to a specific feed (let's call it toggle-feed for now). When the toggle switch is modified, check the toggle-feed value in the Adafruit IO Web Feeds page. You should see it alternating between 1 (on) and 0 (off).

From your Adafruit IO Python code, you can toggle the switch's feed by sending the button's value to a feed.
Code: Select all | TOGGLE FULL SIZE
aio.send(toggle-feed.key, toggle_button)


You should see the toggle block on your dashboard change when you press the button connected to your hardware.

- brent r

brubell
 
Posts: 609
Joined: Fri Jul 17, 2015 10:33 pm

Re: Update Dashboard Toggle Switch from device

by phdsplanning on Mon Oct 21, 2019 11:27 am

Great, thanks.

I realized "toggle_button" is not defined by the API, but needs an assignment. If I assign a '0' or '1' to toggle_button and call the aio.send(), I can see the feed toggle '0' and '1'. However, since the toggle switch has a text label of 'AUTO'/'MANUAL', it did not toggle. The following works now, thanks for pointing me in the right direction:

Code: Select all | TOGGLE FULL SIZE
toggle_button = 'AUTO'
while True:
    if toggle_button == 'AUTO':
        toggle_button = 'MANUAL'
    else:
        toggle_button = 'AUTO'

    aio.send(toggle-feed.key, toggle_button)
    time.sleep(3)

phdsplanning
 
Posts: 2
Joined: Mon Oct 21, 2019 9:28 am

Re: Update Dashboard Toggle Switch from device

by brubell on Mon Oct 21, 2019 3:55 pm

However, since the toggle switch has a text label of 'AUTO'/'MANUAL', it did not toggle.

Ah, makes sense. The set-able text labels are newish. Thanks for the info, I'm sure this topic will come up in the forums again.

The following works now, thanks for pointing me in the right direction:

No problem!

brubell
 
Posts: 609
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.