Community
OpenEnergyMonitor

OpenEnergyMonitor Community

Button usage in EMoncms

Tags: #<Tag:0x00007f681d252600>

I have a local host setup. I want my button in emoncms to operate an led via arduino (which is connected to raspberry pi) on which emoncms is running. Any help please.

Hello @Usman36264

The emoncms dashboard buttons update the emoncms feed that its associated with. You could create a script that reads the value of this feed and updates the arduino.

Here’s an example of the feed value API:

http://localhost/emoncms/feed/value.json?id=10

You could load this into a python script with:

import requests, json

emoncms_apikey = "apikey"
emoncms_server = "http://localhost/emoncms"

reply = requests.get(emoncms_server+"/feed/value.json", params={'id':10,'apikey':emoncms_apikey})
value = reply.text
print(value)

If instead of using the arduino you can connect the LED straight to the RaspberryPi it’s probably a lot simpler, here’s an example using gpiozero:

import requests, json, gpiozero

led1 = gpiozero.LED(9)

emoncms_apikey = "apikey"
emoncms_server = "http://localhost/emoncms"

reply = requests.get(emoncms_server+"/feed/value.json", params={'id':10,'apikey':emoncms_apikey})
value = int(reply.text)

if value>0:
    led1.on()
else:
    led1.off()