Jump to content

Using Network Resource response in a program?


Wes Westhaver

Recommended Posts

Is there a way to use the response from a Network Resource in a ISY994i program?

I have written a REST service that is running on a Linux box and would like to either use the HTTP response code or the HTML body response (JSON or simple text string) to direct the program flow.

I've spent several hours searching the forums and ISY994i docs but can't seem to find an answer.

-Wes

Link to comment

95% of my lights run off of Network resources using the same technique you mentioned.

Each command uses the REST format to talk to (formerly a RPi) another process, running on my polisy, co-resident with IoX using "localhost:XXXX" commands in REST format. At the NRbridge end I parse the commands into separate parameters and operated various routines to operate the light bulbs. I use the MagicHome/LEDenet protocol to control the lights.

My REST commands include On, Off, SetLevels, Effects, and Status (returns status of any bulb or group of bulbs). My last update now includes up to ten bulbs in any command so that those bulbs appear to operate simultaneously. ISY controls which bulbs in the group on the fly so there is no predefined groups/scenes, only dynamic ones.

The responses are not meningful from NR responses. However my status request command can set variables from any device levels and I have found ISY never interprets the responses properly from NRs.

Edited by larryllix
Link to comment
52 minutes ago, larryllix said:

The responses are not meaningful from NR responses. However my status request command can set variables from any device levels and I have found ISY never interprets the responses properly from NRs.

Write another thread in your remote device to set variables for responses. I have one dedicated to a "heartbeat" that tells me if the remote software is alive. A few more variables are used to indicate status when requested.
The REST protocol can work both ways.

  • Like 1
Link to comment

If you are using python3 here are the main routines that send my heartbeat.

 

# Main loop
while(True):
    # Check for incoming command
    httpd.timeout = 5.0
    httpd.handle_request()

    # ISY heartbeat signal
    if time.time() >= ISY_HBlast_sent + ISY_HBperiod:
        if heartbeat != 1:
            heartbeat = 1
        else:
            heartbeat = -1
        write_ISY(heartbeat)
        ISY_HBlast_sent = time.time()

def write_ISY(data):
    ISY_rest = "/rest/vars/set/%s/%s/%s" % (ISY_HBpage, ISY_HBaddr, data)
    get_url = urllib.request.Request('http://' + ISY_IP + ISY_rest) #format the URL
    ISY_authorise = base64.b64encode((ISY_username+":"+ISY_password).encode('utf-8')) #encode it
    get_url.add_header("Authorization", 'Basic %s' % ISY_authorise.decode('utf-8'))
    try:
        r = urllib.request.urlopen(get_url)
        time.sleep(0.001) # allow I/O time slice
        returned = r.read()
        r.close()
        time.sleep(0.001) # allow I/O time slice
    except:
        logging.error("NRBridge: ISY heartbeat send failed!***")
    return

 

  • Like 1
Link to comment
15 hours ago, Wes Westhaver said:

I have written a REST service that is running on a Linux box and would like to either use the HTTP response code or the HTML body response (JSON or simple text string) to direct the program flow.

Meant to comment on this too... you can set variables from outside the ISY using the ISY's REST API, you can also run Program directly from outside the ISY using the REST API.   So your linix box could set a variable, and/or run a specific program or even a specific Then or Else body

https://wiki.universal-devices.com/index.php?title=ISY_Developers:API:REST_Interface

  • Like 1
Link to comment
16 hours ago, larryllix said:

Write another thread in your remote device to set variables for responses. I have one dedicated to a "heartbeat" that tells me if the remote software is alive. A few more variables are used to indicate status when requested.
The REST protocol can work both ways.

That's an interesting way of creating two-way communication between the ISY and an external device.

However, I'm still wondering why the response from a Network Resource isn't acknowledged. Given that the response is a simple integer value, it would make sense to allow an ISY program to use it for flow control.

I wonder if this has ever been put forth as a feature request to the UDI creators?

-Wes

 

Edited by Wes Westhaver
Link to comment
2 hours ago, MrBill said:

Meant to comment on this too... you can set variables from outside the ISY using the ISY's REST API, you can also run Program directly from outside the ISY using the REST API.   So your linix box could set a variable, and/or run a specific program or even a specific Then or Else body

https://wiki.universal-devices.com/index.php?title=ISY_Developers:API:REST_Interface

I have a web application that I created (which runs on a dedicated Raspberry Pi), it provides a simple interface to all of the automation devices in my home. In one case I use the ISY's REST interface to set a variable on the ISY which is used as part of a countdown timer for my Whole-House fan. I really like the REST interface provided by the ISY.

Screenshot from 2023-04-25 12-13-36.png

Edited by Wes Westhaver
Link to comment
47 minutes ago, Wes Westhaver said:

I wonder if this has ever been put forth as a feature request to the UDI creators?

Yes, but this would only work in your specific situation. Most API Calls return something that needs to be parsed then converted into a value accepted by ISY.

The prefered method for this type of integration is a Node Server.  Which will eliminate the need to use variables and network resources.

Link to comment
19 minutes ago, Javi said:

Yes, but this would only work in your specific situation. Most API Calls return something that needs to be parsed then converted into a value accepted by ISY.

The prefered method for this type of integration is a Node Server.  Which will eliminate the need to use variables and network resources.

AFAICT, nobody has discovered a way to make a Node Sever that can operate a group of devices to appear to operate simultaneously. In the past I tried a MagicHome node server and the best time between device operations was one second without mostly failures. Even using NRs, since UDI has never  fixed the variable usage method, at least a 1 second wait must be interjected between any two usages of any NR using variable substitution. With NRbridge I can pass a list of devices in any command and it preps them all before operating them all to appear simultaneously. I don't know of any way to incorporate that into a node server.

Link to comment
1 hour ago, Wes Westhaver said:

That's an interesting way of creating two-way communication between the ISY and an external device.

However, I'm still wondering why the response from a Network Resource isn't acknowledged. Given that the response is a simple integer value, it would make sense to allow an ISY program to use it for flow control.

I wonder if this has ever been put forth as a feature request to the UDI creators?

-Wes

 

That question and bug has been put forward to UDI for the last 6 years and has never been addressed, other that ...it doesn't work. I have attempted to send various packet formulations but none are successful 100% of the time. ISY has no support for the response anyway.

Link to comment
55 minutes ago, larryllix said:

AFAICT, nobody has discovered a way to make a Node Sever that can operate a group of devices to appear to operate simultaneously. In the past I tried a MagicHome node server and the best time between device operations was one second without mostly failures. Even using NRs, since UDI has never  fixed the variable usage method, at least a 1 second wait must be interjected between any two usages of any NR using variable substitution. With NRbridge I can pass a list of devices in any command and it preps them all before operating them all to appear simultaneously. I don't know of any way to incorporate that into a node server.

The context is 2 way communication between ISY and an external device or service which is why Node Servers were created.

Operating a group of devices is dependent on the developer and the devices receiving the commands, so if this can be done in NRbridge is see no reason this could not be done in a node server.  If these devices are network controlled with different IP Addresses then multiple threads must be used so each device can receive the command at about the same time.

  • Like 1
Link to comment
6 hours ago, Javi said:

The context is 2 way communication between ISY and an external device or service which is why Node Servers were created.

Operating a group of devices is dependent on the developer and the devices receiving the commands, so if this can be done in NRbridge is see no reason this could not be done in a node server.  If these devices are network controlled with different IP Addresses then multiple threads must be used so each device can receive the command at about the same time.

Sure but the "scene" method in ISY cannot do simultaneous sends from different devices without causing an annoying popcorn effect. The scene capability must be built into the protocol so that multiple devices can act on the same command as ISY has never supported fast comms to multiple devices, as far as I have ever seen so far.

I have theorised on many ways to create scene groups inside a NS and have ISY able to set them up using  list of devices, perhaps on boot up. Unable to handle any text messages the numbers game gets too complex for most users to use. With my method a constant variable definition must be created for each device but groups can be created and operated on the fly inside ISY programs with no previous scene/group definitions.

Link to comment
Guest
This topic is now closed to further replies.

  • Recently Browsing

    • No registered users viewing this page.
  • Forum Statistics

    • Total Topics
      36.9k
    • Total Posts
      370.2k
×
×
  • Create New...