Help with formatting JSON Commands for a Code Newbie

Hi Guys

I am trying to set up a rule in Rule Machine to turn off the AC when no one is home (house with teenagers who have no concept of turning stuff off).

The AC is a system called MyAir by Advantage Air (Australian made) and will respond to JSON commands which is great. I have tested this by posting command straight into a browser bar and it works fine - as an example I post:

http://10.10.x.x:2025/setAircon?json={"ac1":{"info":{"state":"off"}}} - and the aircon turns off which is great!

SO how do I convert this into a RM friendly command? I see there are two "fields" if you will when looking at posting a JSON command:

Enter URL to send request to - which I assume would be - http://10.10.x.x:2025/setAircon?
Enter body for POST - which I assume would be - json={"ac1":{"info":{"state":"off"}}}

I have tried this and ran the rule but no dice with the aircon going off. I am probably missing something really basic here but would appreciate it if anyone could give me some guidance.

Thanks

Blair

Hello @blair did you manage to figure this out? Anyone can help?

Cheers

Clarence

If you can do this straight from the browser then my assumption is, you need to do a GET request rather than a POST.

In this case, it would be a GET with everything including the JSON on the URL line like you have it in the example, nothing to POST

I tried using Http Get with the whole line in the url but not getting a response from the system. On the browser it works.

Any idea?

How are you doing the GET request...via RM?
Do you get any errors in your logs after sending the request?

Yes via RM. No error in logs. It just shows device 297 info action: Send GET to http://10.0.0.x.... as per the url on the http get

Tried with http post via RM too and whole line on the url. Did not work as well

I've never used RM for http request so I wouldn't be able to help with setup there. I have used @ogiewon's http momentary switch driver. I recommend you give it a shot.

Hubitat/http-momentary-switch.groovy at master · ogiewon/Hubitat · GitHub

1 Like

Thanks installed it but how do I use? Post, get or put? and what do I put into url and body message? Assume that I would have to use application/json?

No way for us to know the details for sure unless the manufacturer gives you specifics.

Since it works in the browser all you should need to do is a GET request and send the complete url just as you would put it in the browser. After you save the settings, turning on the switch would send the http request.

Thanks. Here is the link to the myair API. Post #2

I will try with the GET function within the http momentary switch again. Maybe I didn't do it right.

are you formatting the URL correctly in rule machine? You have to include the http://. I also think that HTTPS does not work, but don't quote me on that one. Turn on logging for actions in your rule and see if that spits anything out.

Advnatge Air publish the guide to their API - I can send it to someone if they need it. Same for me though - works in a browser but not in Hubitat

I have seen in a few posts that use json as the body in RM and only using the entire {}

JSON posting is a b**** and it seems to be a hit or miss.

@blair - Have you considered writing a custom driver or app to do the integration? Even if you don't have the skills yourself there is a reasonable number of developers on this forum who are always happy to help out where they can, including myslef.

I've started writing a driver for my Mitsubishi Electric ducted system, so can provide you with some examples if you want.

Simon

1 Like

Sorry @blair, just read the linked forum post where you have already been getting a whole lot of assistance, didn't mean to discount their help in my last post.

No probs Simon - I am a hardware and network guy - not a programmer unfortunately. I have no idea about JSON etc so will need all the help I can get!

1 Like

Have you figured it out yet? It's not all that complicated once you break it down. Everything has a lablel and a value. For example, this is a snippet of the JSON response from the hubitat MakerAPI:

{ 
        "id":"217",
        "name":"DWME",
        "label":"DWME"
    }

So, in this, the ID is 217 and the name and label are DWME. Each label/value pair gets broken up by a colon and very label and value are wrapped in double quotes. Each set is devided by a comma, if there is another set following, then the whole thing gets wrapped in braces.

So, in your case, you are only sending one set of data, you would have to determine what elements or labels it's looking for, then what the value for each should be.

In Rule Machine, you are going to want to put the whole thing, braces and all, in the body part of the message. The url is just that, just the URL that you will be sending your message to.

If you have authentication you have to pass, that is usually passed as just another lable/value set to the endpoint, like this:

{ 
            "user":"Ryan",
            "pass":"thereISnoSPOON",
            "command":"setLevel",
            "value":"100"
        }

The nice part of using RM, it doesn't care about indentation and returing. So it can all be in one big long line.

{"user":"Ryan","pass":"thereISnoSPOON","command":"setLevel","value":"100"}

Once you have your string, you can take it to a website like this one and check the formatting.