transfer variable or device status between Indigo servers

Posted on
Mon Mar 02, 2020 2:41 pm
boekweg offline
Posts: 70
Joined: Oct 02, 2010
Location: Netherlands

transfer variable or device status between Indigo servers

Hi,

I have a multil level office setup with 4 separate Indigo servers managing the entire building. I want to transfer some variable status from one server to another.
All servers are in the same vlan. I was hoping to use the restfullAPI with the device extensions plugin and use the URL extension but I receive errors if I use that route.

Anybody a good idea?

The functionality I want to achieve is that every server will pass on a value if there is any presence on one of the building levels.

Posted on
Tue Mar 03, 2020 6:44 am
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: transfer variable or device status between Indigo serv

I think I would probably use Indigo's RESTful API and Python to accomplish this. There are likely ways to add more robustness, but you could start with a broadcast method--any time a server's occupied status changes, it could broadcast its status to the other servers. Here's one way.

Each server has four variables: 'server1_occupied', 'server2_occupied', 'server3_occupied, server4_occupied.
Server 1 runs a trigger when 'server1_occupied' changes.
Trigger runs a short Python script to broadcast its status to the other servers (recommend using a linked script and not an embedded script)

Code: Select all
import requests
from requests.auth import HTTPDigestAuth

server_list = ['10.0.1.2', '10.0.1.3', '10.0.1.4']
username = 'USERNAME'
password = 'PASSWORD'
status = indigo.variables['server1_occupied'].value

for server in server_list:
    url = 'http://{0}:8176/variables/server1_occupied?_method=put&value={1}'.format(server, status)
    result = requests.get(url, auth=HTTPDigestAuth(username, password))

indigo.server.log(str(result.status_code))

If each server has different log in credentials, you'll need to amend the script to account for that. Also, this method stores the username and password in clear text within the script, so take that into account for your security situation (and presumes you're requiring a username and password on each server in the first place). The code above may need a bit of tweaking to account for response times, although I believe that the requests module is blocking until a response is received (so it might be fine).

The code is untested, but should be pretty close. If there are problems, post back; I'm happy to help debug.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Mar 03, 2020 7:33 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: transfer variable or device status between Indigo serv

This is probably a classic use case for the use of MQTT.

Setup a MQTT broker on one Indigo server and then each Indigo server can publish topic updates to the MQTT broker and each Indigo server can subscribe to the topics from the other three servers. :)

Posted on
Tue Mar 03, 2020 3:55 pm
boekweg offline
Posts: 70
Joined: Oct 02, 2010
Location: Netherlands

Re: transfer variable or device status between Indigo serv

Thanks guys, I will look into both options

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests