@Gleno0h - that worked perfectly thanks!
How do I check what commands the device has i.e. can I check if there is a toggle command?
Thanks
Nathan
Controlling my Pimatic installation with another raspberry pi
@Gleno0h - that worked perfectly thanks!
How do I check what commands the device has i.e. can I check if there is a toggle command?
Thanks
Nathan
@Nathan-Quick i think you have to look at the device itself. Every switch also has a toggle.
There is alot of info in this forum on how to use the api and get/set variables, press buttons of a dummy device(i use that for my dimmer) or simply toggle/turnon and off.
Some examples;
Devicename/turnOn
Devicename/turnOff
Devicename/toggle
These can be used for all switch protocols i believe.
If you have a button device you would use;
User:pass@ip/api/device/spotjes-schakelaar/buttonPressed?buttonId=spotjes50
Where “spotjes-schakelaar” is the button device id and where “spotjes50” is the button id IN that device.
@Gleno0h said in Controlling my Pimatic installation with another raspberry pi:
@Nathan-Quick i think you have to look at the device itself. Every switch also has a toggle.
There is alot of info in this forum on how to use the api and get/set variables, press buttons of a dummy device(i use that for my dimmer) or simply toggle/turnon and off.
Some examples;
Devicename/turnOn
Devicename/turnOff
Devicename/toggleThese can be used for all switch protocols i believe.
If you have a button device you would use;
User:pass@ip/api/device/spotjes-schakelaar/buttonPressed?buttonId=spotjes50
Where “spotjes-schakelaar” is the button device id and where “spotjes50” is the button id IN that device.
Much appreciated on your help. That really helped.
I’ve got a button now toggling off my GPIO buttons. I’ll look into the APIs. Programming is not something I’m good at but willing to learn. I like a challenge!
@Nathan-Quick great. If you need any help dont hesitate to ask on this forum. There are alot of people that can help you out !
@Gleno0h Cheers!
I’ve been playing some more with my script and breadboard. I’ve got 4 buttons (lights on toggle, lights dim, lights full and tv toggle) and some LEDs to go with them to show the button has been pressed. Here is my basic (and not at all optimised!) code
import RPi.GPIO as GPIO
import time
import os
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(26, GPIO.OUT)
GPIO.setup(19, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(5, GPIO.OUT)
while True:
input_state = GPIO.input(4)
if input_state == False:
print(‘Button 1 Pressed - toggling the Lounge Lights’)
os.system(’./LEDSwitchToogle.sh’)
time.sleep(0.2)
GPIO.output(13, 1)
time.sleep(3)
GPIO.output(13, 0)
input_state = GPIO.input(17)
if input_state == False:
print('Button 2 Pressed - dim the rear lights')
os.system('./DimRear.sh')
time.sleep(0.2)
GPIO.output(26, 1)
time.sleep(3)
GPIO.output(26, 0)
input_state = GPIO.input(27)
if input_state == False:
print('Button 3 Pressed - rear lights on full')
os.system('./FullRear.sh')
time.sleep(0.2)
GPIO.output(19, 1)
time.sleep(3)
GPIO.output(19, 0)
input_state = GPIO.input(6)
if input_state == False:
print('Button 4 Pressed - toggling the TV on and off')
os.system('./TVToogle.sh')
time.sleep(0.2)
GPIO.output(5, 1)
time.sleep(3)
GPIO.output(5, 0)
And here is my basic breadboard
And if you would want something smaller you could consider using an ESP8266, some small housing and some buttons and you’re good to go! (Esp costs about €3 when ordered from China…)
regarding the comment from @stokstaart you could use an esp with espeasy.
there’s an addon for espeasy and pimatic, so this could help to develop a small device espeasy will send it’s variables status to pimatic so you are able to control it via dummy devices. maybe worth a try
pimatic v0.9 has been released!
Support Pimatic and get some free stickers
Like us on Facebook
make it so !
@Nathan-Quick i guess the bash scripts you use (dimrear.sh etc) contain only the api call?
You could execute the curl action from the os.system line so you wont depend on multiple systems.
I also have a code to detect how long a button is pressed, if you want it.
I have one button, a press is reboot, a hold is poweroff.
Thanks all.
I’ve edited my code to tidy it up ad make it a bit more structured.
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import os
# First button - Lights Toggle
but1 = 4
led1 = 13
def ltoggle():
print('Button 1 Pressed - toggling the Lounge Lights')
os.system('curl admin:admin@172.0.0.250:8080/api/device/LLM-01-50-C7-BF-43-0F-34/toggle')
# Second button - Lights Dim
but2 = 17
led2 = 26
def ldim():
print('Button 2 Pressed - dim the rear lights')
os.system('curl admin:admin@172.0.0.250:8080/api/device/brightness-full/buttonPressed?buttonId=LightsDim')
# Third button - Lights Full
but3 = 27
led3 = 19
def lfull():
print('Button 3 Pressed - rear lights on full')
os.system('curl admin:admin@172.0.0.250:8080/api/device/brightness-full/buttonPressed?buttonId=LightsFull')
# Fourth button - TV Toggle
but4 = 6
led4 = 5
def tvtoggle():
print('Button 4 Pressed - toggling the TV on and off')
os.system('curl admin:admin@172.0.0.250:8080/api/device/LL-01-50-C7-BF-76-E5-FE/toggle')
# Status LED
StatLed = 21
# Define LED sequence
def butled(led):
GPIO.output(led, 1)
time.sleep(3)
GPIO.output(led, 0)
# Define flash LED
def flashled(led):
GPIO.output(led, 1)
time.sleep(0.4)
GPIO.output(led, 0)
time.sleep(0.4)
GPIO.output(led, 1)
time.sleep(0.4)
GPIO.output(led, 0)
time.sleep(0.4)
GPIO.output(led, 1)
time.sleep(0.4)
GPIO.output(led, 0)
time.sleep(0.4)
GPIO.output(led, 1)
time.sleep(2)
GPIO.output(led, 0)
# Define GPIO Pins
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(but1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(but2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(but3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(but4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(led1, GPIO.OUT)
GPIO.setup(led2, GPIO.OUT)
GPIO.setup(led3, GPIO.OUT)
GPIO.setup(led4, GPIO.OUT)
GPIO.setup(StatLed, GPIO.OUT)
# Main Loop
try:
while True:
GPIO.output(StatLed, 1)
input_state = GPIO.input(but1)
if input_state == False:
ltoggle()
time.sleep(0.2)
flashled(led1)
input_state = GPIO.input(but2)
if input_state == False:
ldim()
time.sleep(0.2)
flashled(led2)
input_state = GPIO.input(but3)
if input_state == False:
lfull()
time.sleep(0.2)
flashled(led3)
input_state = GPIO.input(but4)
if input_state == False:
tvtoggle()
time.sleep(0.2)
flashled(led4)
except KeyboardInterrupt:
GPIO.cleanup()
GPIO.cleanup()
The issue I have now is that python is maxing the CPU out waiting for a command. I did try briefly to use interrupts but I can’t seem to get it to run in a loop Can anyone help me with that please? As I said, I’m not a programmer.