I've run into an odd problem while trying to use a dashboard Toggle block to reflect the status of a fan. Basically if the fan is turned on I want the toggle block to show ON and vice-versa if the fan turned off. But what is happening is the python script only updates the toggle to Off, never On.
For simplicity's sake I've included only the heart of the code that is to control the toggle block status, which is just a modified version of what I found in your documentation for digital input. The code creates the feed if it doesn't exist then runs the while True: loop where it is supposed to set the toggle to ON, wait 2 seconds and then set the toggle to Off. It will do that until a keyboard interrupt is detected. I've tried the 1 and 0 as both strings and INT. Neither work.
Any help here would be greatly appreciated. Thank you!
# Import standard python modules
import time
# import Adafruit IO REST client.
from Adafruit_IO import Client, Feed, RequestError
# Set to your Adafruit IO key.
# Remember, your key is a secret,
# so make sure not to publish it when you publish this code!
ADAFRUIT_IO_KEY = 'userKey'
# Set to your Adafruit IO username.
# (go to https://accounts.adafruit.com to find your username)
ADAFRUIT_IO_USERNAME = 'username'
# Create an instance of the REST client.
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
try: # if we have a 'digital' feed
digital = aio.feeds('digital')
except RequestError: # create a digital feed
feed = Feed(name="digital")
digital = aio.create_feed(feed)
while True:
aio.send(digital.key, str(1))
time.sleep(2)
aio.send(digital.key, str(0))
# avoid timeout from adafruit io
time.sleep(2)
Python digital input not updating toggle block
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.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
- DoubleTap
- Posts: 36
- Joined: Wed Sep 11, 2013 11:23 pm
- brubell
- Learn User Page
- Posts: 2010
- Joined: Fri Jul 17, 2015 10:33 pm
Re: Python digital input not updating toggle block
The toggle block toggles when the data in the feed matches the Button off text or the button on text.
If you're sending your feed the string ON: And for toggling it off, you'd send the string value OFF: In the Python library, this'd be the same as:and
If you want to send an integer value (such as 1 or 0), you'd need to change the Button On Text or Button Off Text - brent r
If you're sending your feed the string ON: And for toggling it off, you'd send the string value OFF: In the Python library, this'd be the same as:
Code: Select all
aio.send(digital.key, "ON")
Code: Select all
aio.send(digital.key, "OFF")
If you want to send an integer value (such as 1 or 0), you'd need to change the Button On Text or Button Off Text - brent r
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.