ISY4Me Posted April 6, 2023 Posted April 6, 2023 I have two ceiling fans that always power up with lights on after a power outage. I have written some programs to detect this power on state and then turn off the lights, but they don't work. After further digging, I have determined that the light will not programmatically turn off because the sync state is off. When I go to the Bond App and sync the light state, then let the Post Power Outage program run, the light turns off. If we can fix/correct the sync state with the Bond iOS App, is it possible to that we can have the option to add this ability to the Node Server so we can take these odd situations and sync that feature via changing a node state in ISY?
Solution Goose66 Posted April 6, 2023 Solution Posted April 6, 2023 There is an API call to set the stored state vector for a device. However, I have shied away from it because I'm afraid everyone's use case will be different, and the functionality was already accounted for in the Bond mobile app (along with other configuration functions). For example, making it a set function seems counterintuitive, in that people may think they are changing the state, and not setting the stored state. In addition, depending on the device, the current stored state vector may include values for power, light, speed, brightness, breeze, timer, etc., making a set function unwieldy. However, providing specific commands, such as "Set Stored State to Off" is also problematic, in that there would have to be a lot of them to satisfy everyone's desired usages. For example, your light coming on after a power outage seems like a special case, in that I would think most would default to Off. I am open to suggestions for an elegant solution here. Also, for @ISY4Me, you could try adding a network resource to reset the stored state vector. Here is an example CURL command: curl -H "BOND-Token: {token}" -i https://{hostname}/v2/devices/{device_id}/state -X PATCH -d "{\"light\": 1}"
ISY4Me Posted April 6, 2023 Author Posted April 6, 2023 @Goose66 Thank you for the explanation. I agree that my situation is probably unique… having a light like this always power on with light on does seem odd. I will try your suggestion… I have not worked with network resources, but it will be a good excuse to learn.
ISY4Me Posted April 7, 2023 Author Posted April 7, 2023 5 hours ago, Goose66 said: Also, for @ISY4Me, you could try adding a network resource to reset the stored state vector. @Goose66 I am making progress understanding the use of the Curl command for the Local API. But I am finding very little documentation on how to configure such a request in the UD Network Resources. Is it possible you can PM me an import file for resources that demonstrates the setup for executing a CURL command? I have looked at the UD Network Wiki and they seem to dwell on the popular things and not the non-standard implementations as this would be. Any help will be appreciated.
residualimages Posted April 7, 2023 Posted April 7, 2023 34 minutes ago, ISY4Me said: how to configure such a request in the UD Network Resources I have these in my Network Resources still, and they do appear to still work. The example here is to set the belief state of the light to "off" / 0; it could be modified to change the belief state to "on" / 1 with just a single modification of the integer in the Body:
ISY4Me Posted April 7, 2023 Author Posted April 7, 2023 @residualimagesThank you for the response, I had a hard time finding any guidance on setting up this resource. I went through the process of understanding the exact terminal command I needed to issue to accomplish my task. In the end, the following is what proved to work... this was all based on the Bond Bridge API Documentation. My goal was to change the state of the light in the Bond Bridge to On... curl -H "BOND-Token: BondTokenHere" -i http://BondBridgeIPHere/v2/devices/DeviceIDHere/state -X PATCH -d "{\"light\": 1}" Based on what you did in your example I tried to modify what worked in the terminal command above. This is what I came up with... and it did not work(also failed with the escape characters used -X PATCH -d "{\"light\": 1}"). Your body command is different than mine, but I only copied what worked from the terminal command. I don't know what the "_m": 4 is that you used. Where did you learn that this was what was the format required? I went back and tried another variation based on what you did... and your format worked just fine. I am happy that there is a working solution, but being a nerd, I really strive to understand why a particular format is used. Any information you can provide on how you learned to do what you did will be greatly appreciated. Thank you
residualimages Posted April 7, 2023 Posted April 7, 2023 1 hour ago, ISY4Me said: the "_m": 4 is that you used. Where did you learn that this was what was the format required? Was because ISY Network Resources didn't give a PATCH action last I checked. So on the forums for the Bond devices, I had asked their developers for a way to send a PUT command but have it *act like* a PATCH command. As a favor to me, it seemed, they did provide the mechanism - but I believe it did NOT end up documented officially.
ISY4Me Posted April 7, 2023 Author Posted April 7, 2023 (edited) @residualimages Thank you for your help here and also over on the Bond Forum. I was able to find your original discussion in the Bond Forum and that provided a little more information… every little bit helps. So, if I want to extend this method to do an action to TurnLightOff, do I use an "_m": x format or use the standard curl format -X PUT -d "{}" for the body command in ISY Network:Resources? I tried a few variants and all failed. Edited April 7, 2023 by ISY4Me 1
residualimages Posted April 7, 2023 Posted April 7, 2023 (edited) 7 hours ago, ISY4Me said: So, if I want to extend this method to do an action to TurnLightOff, do I use an "_m": x format or use the standard curl format -X PUT -d "{}" for the body command in ISY Network:Resources? I tried a few variants and all failed. You just take what you already made (you can even just copy the existing Network Resource you made, and rename it in ISY Admin Console) and leave everything as-is, just change "light":1 to "light":0. 7 hours ago, ISY4Me said: use an "_m": x format the "_m": 4 command in the body of an ISY Network Resource that is set to use the http PUT action turns the PUT action into a PATCH action -- so anywhere in the Bond API where it says to use a PATCH, you just translate that in your mind to "ISY Network Resource will require me to start my body with "_m": 4. 7 hours ago, ISY4Me said: curl format -X PUT -d "{}" for the body command in ISY Network:Resources The "body" part of any ISY Network Resource will only be the part that goes inside the {} when you call a cURL command. The -X PUT/PATCH/DELETE etc, as well as the leading -d, are not used in the ISY Network Resource, as ISY handles parts of that already natively. Edited April 7, 2023 by residualimages 1
ISY4Me Posted April 7, 2023 Author Posted April 7, 2023 @residualimages Thank you again. You have a way of making all of this seem so logical. You have made a great impact on my baseline understanding of converting a working curl command to a working ISY Network Resource. At this point I am fully functional. With the help I have received from you, the Bond API documentation and all the trial and error learning, I hope that I can deal with any needs that arise going forward.
residualimages Posted April 7, 2023 Posted April 7, 2023 Just now, ISY4Me said: At this point I am fully functional. Great news! It has a little curve in the beginning for each of these things, and (aside a few edge cases like this one you needed), @Goose66's Nodeserver has a way of simplifying steps so most folks don't have to dig into the details. I'm happy you were curious and determined enough to get down into those extra details you needed, though. Some other people in the future may find this useful too. 🤓
ISY4Me Posted April 10, 2023 Author Posted April 10, 2023 On 4/6/2023 at 3:28 PM, Goose66 said: There is an API call to set the stored state vector for a device. However, I have shied away from it because I'm afraid everyone's use case will be different, and the functionality was already accounted for in the Bond mobile app (along with other configuration functions). For example, making it a set function seems counterintuitive, in that people may think they are changing the state, and not setting the stored state. In addition, depending on the device, the current stored state vector may include values for power, light, speed, brightness, breeze, timer, etc., making a set function unwieldy. However, providing specific commands, such as "Set Stored State to Off" is also problematic, in that there would have to be a lot of them to satisfy everyone's desired usages. For example, your light coming on after a power outage seems like a special case, in that I would think most would default to Off. I am open to suggestions for an elegant solution here. Also, for @ISY4Me, you could try adding a network resource to reset the stored state vector. Here is an example CURL command: curl -H "BOND-Token: {token}" -i https://{hostname}/v2/devices/{device_id}/state -X PATCH -d "{\"light\": 1}" @Goose66 Thank you for your original advice. It took a little time to understand the direct communication with the API, but in the end I have the curl commands working and a version installed as a network resource. Sadly we are having too many power outages and we just had another and the commands operated as designed and the fan lights that misbehave with an outage return to normal now with the program that addresses this issue. 2
Recommended Posts