Skip to content

Instantly share code, notes, and snippets.

@goakley
Last active March 22, 2022 17:27
Show Gist options
  • Save goakley/a243eab43617b77a09c24e4f60063590 to your computer and use it in GitHub Desktop.
Save goakley/a243eab43617b77a09c24e4f60063590 to your computer and use it in GitHub Desktop.
zytemp script for use with streetturtle/noobie
import json
import pyzytemp
def main():
t = None
co = None
x = pyzytemp.find()
if x:
temp = x[0]
attempts = 8
for measurement, value in temp.stream():
if measurement == pyzytemp.Measurement.CO2:
co = value
if measurement == pyzytemp.Measurement.T:
t = value
if t is not None and co is not None:
break
attempts -= 1
if attempts <= 0:
break
texts = []
if t is not None:
texts.append(f'{t:.1f}C')
else:
texts.append('??.?C')
if co is not None:
texts.append(f'{int(co)}PPM')
else:
texts.append('???PPM')
print(json.dumps({
'widget': {
'icon': 'activity',
'text': ' '.join(texts),
}
}))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment