New integration help

Hello,

I would like to integrate a older system that I have on home but I need help to go forward.

The system has a web interface and I achieved to understant how it works (I think).

It only accept HTTP GET requests.

1st - I need to autenticate and save the cookie (“curl -d” seams to do the work). The following requests are made with “curl -c” to read the cookie.

2nd - I do not have status by device, just all devices, with names, groups, etc, and it is the only way to get device status, because after device change I just receive “code 200” and not the device status.
I think it should be called periodicaly (like 5 seconds interval)

3rd - To change a device value I just do a GET with device CODE and VALUE.

Do you know any integration identical, to a noob programmer (me) try to adapt?

If not, should I use command line or do I have better solution?

Thank you for your support.

-------- Resquests and responses -------------------

Autentication

curl -d GET "http://192.168.1.99:8888/logas?value=4a8352b6a6ecdb4106b2439aa9e8638a0cdbb16ff3568616f4ccb788d92538fe&value1=4701754001718"
{"Hello":[{"Login":"OK"}]}

Device Status

curl -b GET "http://192.168.1.99:8888/json?devices"
{"devices":{"infrared":[],"all":[{"dst":2,"cod":"MDO6","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":32,"name":"Sancas"},{"dst":1,"cod":"MDO7","status":"S","value":0,"floor":2,"dt":1,"control":2,"room":32,"name":"Tecto Coz"},{"dst":1,"cod":"MDO9","status":"S","value":0,"floor":2,"dt":1,"control":2,"room":32,"name":"Tecto TV"},{"dst":3,"cod":"MDO86","status":"S","value":0,"floor":2,"dt":2,"control":2,"room":32,"name":"Sala Esq."},{"dst":3,"cod":"MDO87","status":"S","value":0,"floor":2,"dt":2,"control":2,"room":32,"name":"Sala Dir."},{"dst":3,"cod":"MDO89","status":"S","value":0,"floor":2,"dt":2,"control":2,"room":2,"name":"Janela"},{"dst":3,"cod":"MDO90","status":"S","value":0,"floor":2,"dt":2,"control":2,"room":2,"name":"Porta"},{"dst":2,"cod":"MDO168","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":25,"name":"Alpendre Sala"},{"dst":2,"cod":"MDO169","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":5,"name":"Entrada"},{"dst":2,"cod":"MDO170","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":5,"name":"Acesso Sala"},{"dst":2,"cod":"MDO172","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":5,"name":"Escadas"},{"dst":2,"cod":"MDO174","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":25,"name":"Apendre entrada"},{"dst":2,"cod":"MDO175","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":25,"name":"Jardim (Pedonal)"},{"dst":2,"cod":"MDO176","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":25,"name":"Jardim (Auto)"},{"dst":8,"cod":"MDO177","status":"S","value":0,"floor":2,"dt":4,"control":1,"room":25,"name":"Recirculação"},{"dst":2,"cod":"MDO180","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":25,"name":"Muro poente"},{"dst":8,"cod":"MDO181","status":"S","value":100,"floor":2,"dt":4,"control":1,"room":25,"name":"Termoacumulador"},{"dst":2,"cod":"MDO183","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":2,"name":"Cozinha"},{"dst":2,"cod":"MDO184","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":37,"name":"Lavandaria"},{"dst":2,"cod":"MDO185","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":25,"name":"Exterior - Cozinha"},{"dst":2,"cod":"MDO186","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":37,"name":"Hall - Lavandaria"},{"dst":2,"cod":"MDO187","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":7,"name":"WC"},{"dst":2,"cod":"MDO188","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":36,"name":"Escritório"},{"dst":2,"cod":"MDO189","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":36,"name":"Escritório - desk"},{"dst":8,"cod":"MDO190","status":"S","value":100,"floor":2,"dt":4,"control":1,"room":7,"name":"Extractor"},{"dst":2,"cod":"MDO193","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":25,"name":"Varanda"},{"dst":8,"cod":"MDO194","status":"S","value":0,"floor":1,"dt":4,"control":1,"room":40,"name":"Tomadas Sótão"},{"dst":2,"cod":"MDO195","status":"S","value":0,"floor":1,"dt":1,"control":1,"room":42,"name":"Roupeiro"},{"dst":2,"cod":"MDO196","status":"S","value":0,"floor":1,"dt":1,"control":1,"room":42,"name":"Ilum. Tecto"},{"dst":2,"cod":"MDO197","status":"S","value":0,"floor":1,"dt":1,"control":1,"room":43,"name":"Ilum. Vestiário"},{"dst":2,"cod":"MDO198","status":"S","value":0,"floor":1,"dt":1,"control":1,"room":40,"name":"Ilum. Corredor"}],"equipments":[{"dst":8,"cod":"MDO177","status":"S","value":0,"floor":2,"dt":4,"control":1,"room":25,"name":"Recirculação"},{"dst":8,"cod":"MDO181","status":"S","value":100,"floor":2,"dt":4,"control":1,"room":25,"name":"Termoacumulador"},{"dst":8,"cod":"MDO190","status":"S","value":100,"floor":2,"dt":4,"control":1,"room":7,"name":"Extractor"},{"dst":8,"cod":"MDO194","status":"S","value":0,"floor":1,"dt":4,"control":1,"room":40,"name":"Tomadas Sótão"}],"climatization":[{"dst":7,"cod":"MDO2474","status":"S","value":76,"floor":2,"dt":19,"control":2,"room":44,"name":"Teste Analogico"}],"blinds":[{"dst":3,"cod":"MDO86","status":"S","value":0,"floor":2,"dt":2,"control":2,"room":32,"name":"Sala Esq."},{"dst":3,"cod":"MDO87","status":"S","value":0,"floor":2,"dt":2,"control":2,"room":32,"name":"Sala Dir."},{"dst":3,"cod":"MDO89","status":"S","value":0,"floor":2,"dt":2,"control":2,"room":2,"name":"Janela"},{"dst":3,"cod":"MDO90","status":"S","value":0,"floor":2,"dt":2,"control":2,"room":2,"name":"Porta"}],"others":[],"sensors":[],"curtains":[],"illumination":[{"dst":2,"cod":"MDO6","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":32,"name":"Sancas"},{"dst":1,"cod":"MDO7","status":"S","value":0,"floor":2,"dt":1,"control":2,"room":32,"name":"Tecto Coz"},{"dst":1,"cod":"MDO9","status":"S","value":0,"floor":2,"dt":1,"control":2,"room":32,"name":"Tecto TV"},{"dst":2,"cod":"MDO168","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":25,"name":"Alpendre Sala"},{"dst":2,"cod":"MDO169","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":5,"name":"Entrada"},{"dst":2,"cod":"MDO170","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":5,"name":"Acesso Sala"},{"dst":2,"cod":"MDO172","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":5,"name":"Escadas"},{"dst":2,"cod":"MDO174","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":25,"name":"Apendre entrada"},{"dst":2,"cod":"MDO175","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":25,"name":"Jardim (Pedonal)"},{"dst":2,"cod":"MDO176","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":25,"name":"Jardim (Auto)"},{"dst":2,"cod":"MDO180","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":25,"name":"Muro poente"},{"dst":2,"cod":"MDO183","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":2,"name":"Cozinha"},{"dst":2,"cod":"MDO184","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":37,"name":"Lavandaria"},{"dst":2,"cod":"MDO185","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":25,"name":"Exterior - Cozinha"},{"dst":2,"cod":"MDO186","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":37,"name":"Hall - Lavandaria"},{"dst":2,"cod":"MDO187","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":7,"name":"WC"},{"dst":2,"cod":"MDO188","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":36,"name":"Escritório"},{"dst":2,"cod":"MDO189","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":36,"name":"Escritório - desk"},{"dst":2,"cod":"MDO193","status":"S","value":0,"floor":2,"dt":1,"control":1,"room":25,"name":"Varanda"},{"dst":2,"cod":"MDO195","status":"S","value":0,"floor":1,"dt":1,"control":1,"room":42,"name":"Roupeiro"},{"dst":2,"cod":"MDO196","status":"S","value":0,"floor":1,"dt":1,"control":1,"room":42,"name":"Ilum. Tecto"},{"dst":2,"cod":"MDO197","status":"S","value":0,"floor":1,"dt":1,"control":1,"room":43,"name":"Ilum. Vestiário"},{"dst":2,"cod":"MDO198","status":"S","value":0,"floor":1,"dt":1,"control":1,"room":40,"name":"Ilum. Corredor"}],"electricvalves":[{"dst":13,"cod":"MDO178","status":"S","value":0,"floor":2,"dt":6,"control":1,"room":25,"name":"Rega Trás - Zona1"},{"dst":13,"cod":"MDO179","status":"S","value":0,"floor":2,"dt":6,"control":1,"room":25,"name":"Rega Trás - Zona2"},{"dst":13,"cod":"MDO1809","status":"S","value":0,"floor":2,"dt":6,"control":1,"room":36,"name":"output virtual anoitecer"},{"dst":13,"cod":"MDO2475","status":"S","value":100,"floor":2,"dt":6,"control":1,"room":44,"name":"Fim de Semana"},{"dst":13,"cod":"MDO2476","status":"S","value":0,"floor":2,"dt":6,"control":1,"room":44,"name":"Estores Bloqueados"},{"dst":13,"cod":"MDO2477","status":"S","value":0,"floor":2,"dt":6,"control":1,"room":44,"name":"flag AlarmeParcial MD"},{"dst":13,"cod":"MDO2478","status":"S","value":0,"floor":2,"dt":6,"control":1,"room":44,"name":"flag AlarmeTotal MD"}]},"subtypes":{"items":[{"id":1,"type":1,"name":"Iluminação Dimmer"},{"id":2,"type":1,"name":"Iluminação On/Off"},{"id":3,"type":2,"name":"Estore"},{"id":7,"type":19,"name":"Ventilação"},{"id":8,"type":4,"name":"Saida On/Off"},{"id":13,"type":6,"name":"Eletroválvula"},{"id":18,"type":8,"name":"Interruptor Normal"},{"id":19,"type":8,"name":"Interruptor Dimmer"},{"id":24,"type":17,"name":"Sensor Presença"},{"id":27,"type":10,"name":"Sensor Incêndio/Falta energia"}]},"types":{"items":[{"id":1,"name":"Iluminação"},{"id":2,"name":"Estores/Cortinas"},{"id":4,"name":"Tomadas"},{"id":6,"name":"Eletroválvulas"},{"id":8,"name":"Interruptor/Botão"},{"id":10,"name":"Sensores Técnicos"},{"id":17,"name":"Sensores Presença/Intrusão"},{"id":19,"name":"Climatização"}]},"resp":200,"rooms":{"items":[{"floor":2,"id":2,"multimedia":1,"name":"Cozinha "},{"floor":2,"id":5,"name":"Hall entrada"},{"floor":2,"id":7,"name":"WC Serviço"},{"floor":2,"id":25,"name":"Exterior"},{"floor":2,"id":32,"name":"Sala de estar"},{"floor":2,"id":36,"name":"Escritório"},{"floor":2,"id":37,"name":"Lavandaria"},{"floor":1,"id":40,"name":"Corredor"},{"floor":1,"id":42,"name":"Q. Camila"},{"floor":1,"id":43,"name":"Vestiário"},{"floor":2,"id":44,"name":"Quadro Alarme"}]},"floors":{"items":[{"id":1,"name":"Piso+1"},{"id":2,"name":"Piso-0"}]}}

Turn OFF device

curl -b GET "htp://192.168.1.99:8888/control?device&cod=MDO6&value=0"
{"resp":200}

I’ve made new discover.
I just have to make the GET with session id active, like the following:

curl -X GET "http://192.168.1.99:8888/json?devices" -H "Cookie: IDHTTPSESSIONID=vCJCzI8g4OSKnSp"

So, does anybody know the right way to create this integration?

Hi Jorge,

Do you know python? The first step should be to write a script in python which could login on your system, list the devices and then query them. After you have this, you should be able to look at another integration and just change the query part. Take a look at the “requests” python library as it should work as “curl” replacement.

Thanks clyra for you answer.

Unfortunatly don’t know Phyton… just some PHP.

I’m trying to find some simple component or script to guide me but if you know one I apreciate your help.

I can help with the component part, but how to grab the info will need some try and error. This is why I suggested writing a script (without HA) first. Take a look at some python requests library examples. You may find something very close to what you need.

I’ll came back when i have someting more. Thank you.

To add to what @clyra says, writing a python module separate from home assistant is the correct way forward from an architecture perspective. In fact is is a requirement (although if it is just for your own private use, you don’t need to worry about the formal requirements. It is however good practice :slight_smile: )

Hi nickrout,

Thank you for your message. When you say “writing a separate module” are you refering to this:

I want to take some time for doing this but I’m on very start.

Do you know some virtual machine with Python and an IDE (autocomplete one)… Something ready to take off?

Por do you suggest an environment to make an easy start?

After a search I’ve decided to use Wing-Personal for windows to do this. It is great to start.

Next week I hope having a working solution to present and get help to make it as module.

1 Like