Skip to content

Commit

Permalink
Updated external switch example. #811
Browse files Browse the repository at this point in the history
  • Loading branch information
theyosh committed Aug 25, 2023
1 parent 69a09f4 commit 6d55f25
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions contrib/external_switch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

# This is just an example script to test the functionality for TerrariumPI. It is also a reference for implementing your own scripts
# All installed python libraries are available in this custom script

import sys
from pathlib import Path
Expand All @@ -9,13 +10,14 @@
# Enable debug to see if the script is running correctly. The output will be at /tmp/terrariumpi_test_relay_script.txt
DEBUG = True

# When there is no extra arguments, TerrariumPI expect a float value to return the current state.
# When there is no extra arguments, TerrariumPI expect a float value above 0.0 to return the current state.
# Return -1.0 when not supported.
if len(sys.argv) == 1:
# Call your code here....
# Call your readout or current state code here....
# In this demo no read out option, return default value of -1.0
print("-1.0")

# Here we start to set the relay to the requested state: Off (=0) or On (>100)
else:
try:
value = int(float(sys.argv[1]))
Expand All @@ -30,17 +32,16 @@

if value == 0:
if DEBUG:
with debug_file as output:
output.write_text(f"[{datetime.now()}] Toggle power switch to state OFF => {value}\n")
debug_file.write_text(f"[{datetime.now()}] Toggle power switch to state OFF => {value}\n")

# Call your code here....
# Call your code here to toggle the relay to OFF ....

else:
if DEBUG:
with debug_file as output:
output.write_text(f"[{datetime.now()}] Toggle power switch to state ON or dimming value: => {value}\n")
debug_file.write_text(f"[{datetime.now()}] Toggle power switch to state ON or dimming value: => {value}\n")

# Call your code here....
# Call your code here to toggle the relay to ON ....
# Or when using it as a dimmer, use the `value` to set the dimmer

# This is optional, and will not be used in TerrariumPI
print(value)

0 comments on commit 6d55f25

Please sign in to comment.