Giter Site home page Giter Site logo

Control smartplugs? about sector HOT 19 CLOSED

MrDuco avatar MrDuco commented on September 26, 2024
Control smartplugs?

from sector.

Comments (19)

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024 2

Based on the great input from @Ubiquitous-X above I will implement the switch and release a new beta so you can test and see what works or not :)
Will try to get that sorted during the weekend.

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

Not really as I don't have Sector anymore and therefore no plugs either so unless I can work with someone who has and can borrow their account it's not being possible... And since it's an alarm we are taking about I feel pretty sure the chance someone handing their account to me is pretty slim.

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

Thanks for your reply. I'm currently trying to develop this myself now with your code as base.

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

If you learn which url's is used with parameters to control them then let me know and it's quite simple to add into the code as the switch platform.

from sector.

Ubiquitous-X avatar Ubiquitous-X commented on September 26, 2024

The url for checking plugs and get their ID´s and status is https://mypagesapi.sectoralarm.net/SmartPlugs/GetsmartPlugsForPanel
The url for switching them is https://mypagesapi.sectoralarm.net/SmartPlugs/SwitchSmartPlug where you can send the id of the plug with the parameter on or off.
I made a fork from the sectoralarmlib by peroyvind where I get the ID´s of the plugs and switch them on or off. Maybe that is some help. https://github.com/Ubiquitous-X/sectoralarmlib
I should add that I am no programmer. I got it to work by copy/paste until it worked, so to say.

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

thanks for the URL. Can't get it to work with aiohttp thou.
There are some differences between your (Ubiquitous-X) script and the (gjohansson-ST) custom component that I cannot figure out how it works
The base url is https://mypagesapi.sectoralarm.net vs https://mypagesapi.sectoralarm.net/api
/User/Login vs /Login/Login
If I access https://mypagesapi.sectoralarm.net and login and then uses the same browser session to access https://mypagesapi.sectoralarm.net/SmartPlugs/GetsmartPlugsForPanel?id=xxxxx it works.

When I try to access it thru aiohttp after successful login thru, https://mypagesapi.sectoralarm.net/api/Login/Login (I get 200 OK and auth token back), I can get tempratures and FullPanel eg everything except the SmartPlugs.

If I try https://mypagesapi.sectoralarm.net/SmartPlugs/GetsmartPlugsForPanel?id=xxxxx I get 401 unauthorized as response. There is no api/SmartPlugs/GetsmartPlugsForPanel?id=xxxxx.

Any tips on this?
Sorry if this is the wrong forum to discuss this.

from sector.

klercker avatar klercker commented on September 26, 2024

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

Based on the great input from @Ubiquitous-X above I will implement the switch and release a new beta so you can test and see what works or not :) Will try to get that sorted during the weekend.

Wow! Many Thanks @gjohansson-ST !!!!

If of any use here is the Json response when accessing https://mypagesapi.sectoralarm.net/SmartPlugs/GetsmartPlugsForPanel?id=xxxxx&WithStatus=true
image

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

Hi guys
Looking at this your lib that you refer too is using the webpage and not the api (which I am using).
Is there any chance you can do a MITM and see which url's and content is used when using the app instead?
Personally I use Charles but it cost money but also used https://docs.mitmproxy.org/stable/ in the past which is free (but more difficult to use).
Other alternative is of course to switch completely to use your lib instead and publish it as such.

What do you think?

from sector.

Ubiquitous-X avatar Ubiquitous-X commented on September 26, 2024

I believe I managed to sniff out the api call from the Sector app on my iPhone.
A GET request is made from the iOS app to https://mypagesapi.sectoralarm.net/api/Panel/GetSmartplugStatus?panelId=xxxxxxxx. In the response the Id SerialNo and Status of the smartplug(s) are delivered.

When I turn on the smartplug in the Sector app, a POST request is made to https://mypagesapi.sectoralarm.net/api/Panel/TurnOnSmartplug?switchId=xxxxxxx&panelId=xxxxxxxx. The switchId is the the same as the Id in the first GET request.

And when I turn off the smartplug a POST request is made to https://mypagesapi.sectoralarm.net/api/Panel/TurnOffSmartplug?switchId=xxxxxxx&panelId=xxxxxxxx

Hope this makes it one step closer

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

I believe I managed to sniff out the api call from the Sector app on my iPhone. A GET request is made from the iOS app to https://mypagesapi.sectoralarm.net/api/Panel/GetSmartplugStatus?panelId=xxxxxxxx. In the response the Id SerialNo and Status of the smartplug(s) are delivered.

When I turn on the smartplug in the Sector app, a POST request is made to https://mypagesapi.sectoralarm.net/api/Panel/TurnOnSmartplug?switchId=xxxxxxx&panelId=xxxxxxxx. The switchId is the the same as the Id in the first GET request.

And when I turn off the smartplug a POST request is made to https://mypagesapi.sectoralarm.net/api/Panel/TurnOffSmartplug?switchId=xxxxxxx&panelId=xxxxxxxx

Hope this makes it one step closer

Lovely. Only thing missing is the json you get back. Did you get that?

from sector.

Ubiquitous-X avatar Ubiquitous-X commented on September 26, 2024

The json that is sent back after the GET request is:

[
  {
    "Consumption": "-1",
    "DisplayScenarios": false,
    "Id": "9xxxxx0",
    "Label": "Smartplug",
    "PanelId": null,
    "SerialNo": "2xxxxxxxxxE",
    "Scenarios": null,
    "Status": "On",
    "TimerActive": false,
    "TimerEvents": null,
    "TimerEventsSchedule": null
  }
]

The panelId is null, as you see, but this is the returned call after a successful poll of status. The plugs aren't a part of the panel per se, and maybe thats why it is listed as null.

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

The json that is sent back after the GET request is:

[
  {
    "Consumption": "-1",
    "DisplayScenarios": false,
    "Id": "9xxxxx0",
    "Label": "Smartplug",
    "PanelId": null,
    "SerialNo": "2xxxxxxxxxE",
    "Scenarios": null,
    "Status": "On",
    "TimerActive": false,
    "TimerEvents": null,
    "TimerEventsSchedule": null
  }
]

The panelId is null, as you see, but this is the returned call after a successful poll of status. The plugs aren't a part of the panel per se, and maybe thats why it is listed as null.

Perfect. All I need.
Will get it sorted now.
Thanks

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

Hi both
I have now released a new beta that should (if all works) introduce the switch platform.
I have rewritten so much of the code and since I can not test it I hope that you will. Please raise new issues for everything that doesn't work.

@Ubiquitous-X given that it seems you can get out what is sent etc. to Sector and based on above it seems as Sector has changed quite a bit on their api e.g. introducing new end-points.
Is it possible for you to provide a new full set of:

  • url
  • message header on post and get commands
  • return json on post and get commands
    You can send per e-mail if you wish and can do it.
    Thanks

from sector.

MrDuco avatar MrDuco commented on September 26, 2024

AWSOME! I will start testing asap!

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

I'm sure it will spit out all kind of errors I made all along the way here so obviously the best is if you check the logs, correct the code as you go and then feedback to me (either as issues or simply make a PR 😄 )
Thanks

from sector.

Ubiquitous-X avatar Ubiquitous-X commented on September 26, 2024

@gjohansson-ST I sent you an email with what I believe should be the complete json needed

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

@gjohansson-ST I sent you an email with what I believe should be the complete json needed

Cool. Will check and get back to you.

from sector.

gjohansson-ST avatar gjohansson-ST commented on September 26, 2024

Solved in latest release v0.3.4

from sector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.