Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use the custom statusPattern #20

Closed
IT-Lueg opened this issue Nov 22, 2018 · 9 comments
Closed

how to use the custom statusPattern #20

IT-Lueg opened this issue Nov 22, 2018 · 9 comments

Comments

@IT-Lueg
Copy link

IT-Lueg commented Nov 22, 2018

Can you please help me ?
I dont know what I am doing wrong...

code

cmd

[2018-11-22 09:06:42] [shelly2 2] Body of status response is: '{"ison":true,"has_timer":false,"overpower":false,"is_valid":true}'
[2018-11-22 09:06:42] [shelly2 2] Switch is currently OFF

Can you please help me to find the right statusPattern?

@Supereg
Copy link
Owner

Supereg commented Nov 22, 2018

I‘m gonna look into it. Please have some patience, since I got very little time at the moment.

@IT-Lueg IT-Lueg changed the title how to use the custom stausPattern how to use the custom statusPattern Nov 26, 2018
@IT-Lueg
Copy link
Author

IT-Lueg commented Nov 26, 2018

Okay, thanks, then I'll wait for an answer from you.

@Supereg
Copy link
Owner

Supereg commented Nov 27, 2018

So I tried testing your configuration and couldn't find mistakes. So you get a clear 'works on my machine' 😄

However I published an update v0.5.13 which prints some more debug information. Would be great if you could update your homebridge-http-switch plugin and poste the log output. A snippet from everything printed when the plugin is loaded as well when a status requests is performed would be great.

Maybe you could also double check (with curl or something) if your pattern exactly matches the response from the shelly device. Every space or new line is relevant there.
Also the relevant json property from the response is 'ison' (isn't it?). Do the other properties change in runtime?

I noticed that this is some sort of Shelly Switch? I ordered some for me some weeks ago, they should get to me hopefully soon. Maybe I could help you more. However they need to arrive first 😅

Greets

@IT-Lueg
Copy link
Author

IT-Lueg commented Nov 28, 2018

so first I updatet the homebridge-http-switch plugin to version 0.5.13
version

When I start homebridge this is the output I get for homebridge-http-switch:
load1
load2

as soon as homebridge is started, I open the "home" app on my smartphone, switch on the "shelly" 😅 and get the following output:
turnon

shelly is now turned on...
shelly_check
web

if I close the "Home" app now and open it again I get the following output
check

When I use curl (I hope I'm doing it right) I get the following message...
curl

That's right. It´s a "shelly2".
Oh, that's great. I hope you get it soon 👍

Thanks for the great support.
I really appreciate that. 🥇

@IT-Lueg
Copy link
Author

IT-Lueg commented Nov 28, 2018

Also the relevant json property from the response is 'ison' (isn't it?). Do the other properties change in runtime?

Thats right, "ison" is the relevant property..

web
web2

I don't think the other parameters would change that way.
https://shelly-api-docs.shelly.cloud/#shelly-switch-relay-index

shelly_doc

@Supereg
Copy link
Owner

Supereg commented Nov 28, 2018

Okay as I assumed there is probably some sort of character encoding problem in the config. I could be wrong what the exact cause is. Could also be confusion about the config file on your side.
When you look closely into the logs where it prints the statusPattern which is configured you can read: '..."iseon":true....'
So please double check your config, maybe retype the specific part.

@IT-Lueg
Copy link
Author

IT-Lueg commented Nov 28, 2018

That´s it ! 🙈
Now everything is working 👌

But why didn't it work with this configuration before ?

Can you please help me ?
I dont know what I am doing wrong...

code

cmd

[2018-11-22 09:06:42] [shelly2 2] Body of status response is: '{"ison":true,"has_timer":false,"overpower":false,"is_valid":true}'
[2018-11-22 09:06:42] [shelly2 2] Switch is currently OFF

Can you please help me to find the right statusPattern?

My config now for the 2 Switches:

 {
            "accessory": "HTTP-SWITCH",
            "name": "shelly2 1",
            "switchType": "stateful",
            "onUrl": {
                "url": "http://192.168.1.207/relay/0?turn=on",
                "method": "POST"
            },
            "offUrl": {
                "url": "http://192.168.1.207/relay/0?turn=off",
                "method": "POST"
            },
            "statusUrl": {
                "url": "http://192.168.1.207/relay/0",
                "method": "GET"
            },
            "statusPattern": "{\"ison\":true,\"has_timer\":false,\"overpower\":false,\"is_valid\":true}"
        },
        {
            "accessory": "HTTP-SWITCH",
            "name": "shelly2 2",
            "switchType": "stateful",
            "onUrl": {
                "url": "http://192.168.1.207/relay/1?turn=on",
                "method": "POST"
            },
            "offUrl": {
                "url": "http://192.168.1.207/relay/1?turn=off",
                "method": "POST"
            },
            "statusUrl": {
                "url": "http://192.168.1.207/relay/1",
                "method": "GET"
            },
            "statusPattern": "{\"ison\":true,\"has_timer\":false,\"overpower\":false,\"is_valid\":true}"
        }

@IT-Lueg IT-Lueg closed this as completed Nov 28, 2018
@Supereg
Copy link
Owner

Supereg commented Nov 28, 2018

But why didn't it work with this configuration before ?

I have absolutely no idea 😅 But happy to hear, that it works now.

A little 'pro' tip, I don't know how well you know regex pattern. But in your case it would be enough to set the statusPattern to "\"ison\":true". This would ensure that the pattern matching is unaffected when the other values of the json changes somehow.
The pattern is matched if the pattern is contained in the text you want to test. Otherwise if you want to be sure that the complete response matches your body you can prepend ^ and append $ to your pattern wich match to the beginning or the end of a string.
Don't know if I explained it well enough, what I mean with that is that the pattern true matches the text 'true' as well as 'asdtrue asdkw'. However the pattern ^true$ only matches the first one.

@cgilis
Copy link

cgilis commented Nov 13, 2020

Just for reference:

This worked for me (Shelly Dimmer):

{
    "accessory": "HTTP-SWITCH",
    "name": "NAME",
    "switchType": "stateful",
    "onUrl": {
        "url": "http://192.168.X.X/light/0?turn=on",
        "method": "POST"
    },
    "offUrl": {
        "url": "http://192.168.X.X/light/0?turn=off",
        "method": "POST"
    },
    "statusUrl": {
        "url": "http://192.168.X.X/light/0",
        "method": "GET"
    },
    "statusPattern": "\"ison\":true"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants