..
2016-11-28 14:20:39 +00:00
2016-11-28 14:20:39 +00:00
2016-11-28 14:20:39 +00:00
2016-11-28 14:20:39 +00:00
2016-11-28 14:20:39 +00:00

[Documentación en inglés y español]

Orvibo S20 Domoticz
======================

I made some slight modifications to adapt the PHP programming code from third parties to Domoticz.
Thanks for the code to pcp135 / Orvibo https://github.com/pcp135/Orvibo (Orvibo Class for switching plugs) and
sergejey / butler-orvibo https://github.com/sergejey/majordomo-orvibo (code to obtain the status)

The work I did was test the code of pcp135 to get it to work and create a small script to communicate with Domoticz.
On the code of sergejey what I did was break a bit the code by removing a lot of to get communication with switchs to know the status and send it to Domoticz.
Since I do not have time, I can not improve it, clean it and put everything in a nice class, but the important thing is that it works.

NEEDS
---------
Its need Apache + PHP on the same machine as Domoticz. In my case, it is a Windows Domoticz on port 8080. I installed XAMPP on port 80 and 444 (SSL 443 was busy and Apache did not start).
Important: S20 Orvibo outlets must be previously configured for the network that will work.


THE CODE
--------
The code consists of two parts:

1. Orvibo.php and s20.php
With these codes, we can turn on and off Orvibo plugs S20.
We must know the MAC address of the socket (you can use any network scanning as netscan program or command line program from Andrius Štikonas https://stikonas.eu/wordpress/2015/02/24/reverse-engineering-orvibo-s20 -socket / or perhaps even the other side of the module).
Create the folder s20 in the root of our apache server and copy the files. It will use the URL:
http://IP-DOMOTICZ/s20/s20.php?mac=accf23514ddd&accion=on
http://IP-DOMOTICZ/s20/s20.php?mac=accf23514ddd&accion=off
At this point you must turn on and off quickly any plug.

2. cron.php and cron.bat (windows)
This code is responsible for launching a status request to the network by UDP port 10000 and listening for a response, it generates an array and sends the status of the plugs to Domoticz. This is needed if we turn on the plug or turn off manually and want to update their status to Domoticz (JSON).
We can try to launch the URL and it should return debug code.
http://IP-DOMOTICZ/s20/cron.php


USE DOMOTICZ
--------
Step 1: Create a virtual switch through Setup > Hardware.
Name: Orvibo
Type: Dummy

Step 2: Create as many virtual switches and outlets Orvibo S20 we have (remember that plugs should already be pre-configured and running on your network), assign them a name and write down IDX (Setup > Devices).

We have our dummy plugs that do absolutely nothing.

Step 3: Include switches and assign a name through Setup > Devices > (Arrow). The switches will appear in Switches section but still does not work.

Step 4: Editing a plug and fill On Action and Off Action with:
http://localhost/s20/s20.php?mac=MACADDRESS01&accion=on
http://localhost/s20/s20.php?mac=MACADDRESS01&accion=off
Where MACADDRESS01 is the MAC address of the plug we are configurin and have previously tried before throwing the URL and worked OK.
Save it.

At this moment our plug works! Turns on and off quickly. We can make rules and play with it.


Now you must run the CRON if the state outlet outside Domoticz changes manually. This requires modifying the PHP and configure it. I have set the CRON every 5 minutes (in my Windows machine).


CONFIGURATION
------
cron.php must be configured manually to update the state correctly to Domoticz JSON.
To do this, edit the cron.php and modify the lines regarding:
$domoticz_server > the base URL of Domoticz, for example http://localhost:8080
and several lines
$mienchufe['accf23514ddd'] = '106'; // Description ddd
$mienchufe['accf23514eee'] = '107'; // Description eee
which it is an array with the MAC address and the IDX assigned to the virtual plug in Domoticz.


Chim Pum!

Eduardo Pagán
http://blog.eduardopagan.com/







Orvibo S20 a Domoticz
======================

He hecho algunas modificaciones y pequeñas programaciones para adaptar el código PHP de terceros a Domoticz.
Gracias por el código a pcp135 / Orvibo https://github.com/pcp135/Orvibo (Clase Orvibo para encender y apagar los enchufes) y
sergejey / mayordomo-orvibo https://github.com/sergejey/majordomo-orvibo (código para conocer el estado de los mismos)

El trabajo que hice fue probar el código pcp135 hasta conseguir que funcionara y crear un pequeño script para la comunicación con Domoticz.
Sobre el código de sergejey lo que hice fue romperlo un poco quitando mucho código hasta conseguir la comunicación con los enchufes para saber el estado y enviarlo a Domoticz.
Como no dispongo de tiempo, no puedo mejorarlo, limpiarlo y meterlo todo en una bonita clase, pero lo importante es que funciona.

NECESIDADES
---------
Lo más cómodo es disponer de Apache+PHP en la misma máquina que Domoticz. En mi caso, es un Windows con Domoticz en el puerto 8080. He instalado XAMPP en el puerto 80 y 444 (ya que el 443 SSL estaba ocupado y no iniciaba).
Importante: Los enchufes de Orvibo S20 previamente deben de estar configurados para la red en la que vamos a trabajar.


EL CÓDIGO
--------
El código consta de dos partes:

1. Orvibo.php y s20.php
Con estos códigos, podemos encender y apagar los enchufes Orvibo S20.
Debemos conocer la dirección MAC del enchufe (podemos utilizar algún programa escaneo de red como netscan o el programa de línea de comandos de Andrius Štikonas https://stikonas.eu/wordpress/2015/02/24/reverse-engineering-orvibo-s20-socket/ o quizás incluso la otra parte del módulo).
Crearemos la carpeta s20 dentro de la raíz de nuestro servidor apache y copiaremos los ficheros y emplearemos la URL:
http://IP-DOMOTICZ/s20/s20.php?mac=accf23514ddd&accion=on
http://IP-DOMOTICZ/s20/s20.php?mac=accf23514ddd&accion=off
En este punto se debe encender y apagar con rapidez.

2. cron.php y cron.bat (windows)
Este código se encarga de lanzar una petición de estado a la red por UDP puerto 10000 y se queda escuchando la respuesta, genera un array y envía el estado de los enchufes a Domoticz. Esto es por si encendemos el enchufe o lo apagamos de forma manual y queremos que se actualice su estado en Domoticz por JSON.
Podemos probar a lanzar la URL y debería de retornar código debug.
http://IP-DOMOTICZ/s20/cron.php


USO EN DOMOTICZ
--------
Paso 1: Creamos un interruptor virtual a través de Setup > Hardware.
Nombre: Orvibo
Tipo: Dummy

Paso 2: Creamos tantos interruptores virtuales como enchufes Orvibo S20 tengamos (recuerdo que ya deben estar preconfigurados y funcionando en la red), les asignamos un nombre y nos anotamos el IDX (Setup > Devices).

Ya tenemos nuestros enchufes Dummy que no hacen absolutamente nada.

Paso 3: Los incluimos en nuestros Switches y les ponemos nombre. Nos aparecerán en Switches pero seguirán sin hacer nada.

Paso 4: Editamos un enchufe y rellenamos On Action y Off Action con:
http://localhost/s20/s20.php?mac=MACADDRESS01&accion=on
http://localhost/s20/s20.php?mac=MACADDRESS01&accion=off
Donde MACADDRESS01 es la dirección MAC de ese enchufe y que previamente hemos probado antes lanzando a mano la URL y funcionaba OK.
Guardamos.

¡Desde este momento nuestro enchufe ya funciona! Enciende y apaga rápidamente. Ya podemos hacer reglas y jugar con él.


Ahora hay que ejecutar el CRON por si se modifica el estado del enchufe de forma física fuera de Domoticz. Para ello hay que modificar el PHP y configurarlo. Yo he puesto el CRON cada 5 minutos en Windows. Cada uno que lo haga como quiera (si no se sabe, buscar en Google).
Si se utiliza el .bat habrá que modificar las rutas.


CONFIGURACIÓN
------
En el caso del cron.php hay que configurarlo de forma manual para que actualice el estado correctamente a Domoticz por JSON.
Para ello editamos el cron.php y modificamos las líneas referentes a:
$domoticz_server donde indicaremos la URL base de Domoticz, por ejemplo http://localhost:8080
y varias líneas de
$mienchufe['accf23514ddd'] = '106';	// Description
$mienchufe['accf23514eee'] = '107';	// Description
que es un array donde se indica la MAC y la IDX asignada en Domoticz a ese enchufe virtual.


Chim pum!

Eduardo Pagán
http://blog.eduardopagan.com/