• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


Shelly device
#1
Hi!

As 433 Mhz is always susceptible to RF interference, I am now experimenting with shelly-devices (https://shelly.cloud/).

This is a small relay unit, connected by WiFi, which can be placed behind a switch and connected to is. So the relay and the connected lamp  can be switched either by the physical switch or by http. I't is similar to Sonoff flashed with Tasmota. But you can use it out of the box without flashing. And most importent to me it can work without any cloud connection.

Because I already have a lot of 433 MHz-devices which will not all be replaced by shelly, I would like to mix 433 and shelly under the nice clean GUI of pilight.

I've now integrated the shelly by the following trick I found in the Forum. This are the relevant parts of my config
Code:
        "ShellyOn": {
            "protocol": [ "program" ],
            "id": [{
                "name": "ShellyOn"
            }],
            "program": "php /home/pi/ShellyOn.php",
            "arguments": "",
            "stop-command": "",
            "start-command": "php /home/pi/ShellyOn.php",
            "state": "stopped",
            "pid": 0
        },
        "ShellyOff": {
            "protocol": [ "program" ],
            "id": [{
                "name": "ShellyOff"
            }],
            "program": "php /home/pi/ShellyOff.php",
            "arguments": "",
            "stop-command": "",
            "start-command": "php /home/pi/ShellyOff.php",
            "state": "stopped",
            "pid": 0
        },
        "Hof": {
            "protocol": [ "generic_switch" ],
            "id": [{
                "id": 97
            }],
            "state": "off"
        },

Code:
        "HofAn": {
            "rule": "IF Hof.state == on THEN switch DEVICE ShellyOn TO running",
            "active": 1
        },
        "HofAus": {
            "rule": "IF Hof.state == off THEN switch DEVICE ShellyOff TO running",
            "active": 1
        },

The scripts to switch on and off are
Code:
<?php

printf( "Shelly.php Version 1.0.0 2019.02.23\n" );

//phpinfo();

$response = file_get_contents( "http://shelly-Hoflicht.fritz.box/relay/0?turn=on" );
printf( "Result=%s\n", $response );


?>
and
Code:
<?php

printf( "Shelly.php Version 1.0.0 2019.02.23\n" );

//phpinfo();

$response = file_get_contents( "http://shelly-Hoflicht.fritz.box/relay/0?turn=off" );
printf( "Result=%s\n", $response );


?>
As the shelly has the possibility to read out the actual state (indeprendent of switching physical of by http, I have a 3rd script to update pilight
Code:
<?php

printf( "Shelly.php Version 1.0.0 2019.02.23\n" );

//phpinfo();

$oldIson=false;
$newIson=false;

while( true )
{
    $response = file_get_contents( "http://shelly-Hoflicht.fritz.box/relay/0" );
//    printf( "Result=%s\n", $response );
    if ( strpos( $response, "\"ison\":true" ) == false )
        $newIson = false;
    else
        $newIson = true;
//    printf( "oldIson=%d newIson=%d\n", $oldIson, $newIson );
    if ( $newIson != $oldIson )
    {
        if ( $newIson )
        {
            printf( "Hoflicht angeschaltet\n" );
            $response = file_get_contents( "http://raspberrypi.fritz.box:5001/control?device=Hof&state=on" );
////            printf( "%s\n", $response );
        }
        else
        {
            printf( "Hoflicht ausgeschaltet\n" );
            $response = file_get_contents( "http://raspberrypi.fritz.box:5001/control?device=Hof&state=off" );
//            printf( "%s\n", $response );
        }
        $oldIson = $newIson;
    }
    sleep( 1 );
}

?>

So this is of course only quick and dirty and not really usable for a larger amount of shelly-devices. What I like to have is a new protocol with the URL and a poll-time for the update of external switch-events. Something like
Code:
        "Hof": {
            "protocol": [ "shelly_switch" ],
            "id": [{
                "URL": "xxx.xxx.xxx.xxx",
                "polltime": 1
            }],
            "state": "off"
        },
What would be necessary to implement this? Is in the c-part or in lua? I could write some code, but I'm normally developing for Windows and not used to the unix build chain
Uli
 
Reply
#2
Nice Smile
 
Reply
#3
But what about making a hardware module to support these devices natively?
 
Reply
#4
(03-09-2019, 05:45 PM)curlymo Wrote: But what about making a hardware module to support these devices natively?

What do you mean by hardware module? Thats different from a protocol ??
 
Reply
#5
The hardware module is the interface to the outside world. The 433.92Mhz protocol just tell pilight that they want to sent a pulse stream, but not how. The hardware module translate those requests to an actual hardware-wise action. And in case of the 433.92Mhz protocol, this can currently be the 433gpio which translates those requests to plain gpio actions or the 433nano which translates those requests to arduino nano actions. A new RaspyRFM module is currently being created to have yet another hardware device supported to sent out 433.92Mhz signals.

So, you could built a hardware module that interfaces between the shelly devices and new shelly protocols. Maybe reading this PR helps getting the idea:
https://github.com/pilight/pilight/pull/429

Just think about a protocol called e.g, shelly_switch with the same properties as the generic_switch and any other switch. The shelly hardware module listens to those shelly_switch protocols and translates the actions of the shelly_switch to shelly actions, just as you did now in your PHP script.
 
Reply
#6
(03-10-2019, 10:12 AM)curlymo Wrote: The hardware module is the interface to the outside world. The 433.92Mhz protocol just tell pilight that they want to sent a pulse stream, but not how. The hardware module translate those requests to an actual hardware-wise action. And in case of the 433.92Mhz protocol, this can currently be the 433gpio which translates those requests to plain gpio actions or the 433nano which translates those requests to arduino nano actions. A new RaspyRFM module is currently being created to have yet another hardware device supported to sent out 433.92Mhz signals.

So, you could built a hardware module that interfaces between the shelly devices and new shelly protocols. Maybe reading this PR helps getting the idea:
https://github.com/pilight/pilight/pull/429

Just think about a protocol called e.g, shelly_switch with the same properties as the generic_switch and any other switch. The shelly hardware module listens to those shelly_switch protocols and translates the actions of the shelly_switch to shelly actions, just as you did now in your PHP script.

Hi Curlymo

Now that the new version runs very stable, I would like to come back to the topic of integrating shelly's into pilight. I had a look at the discussion with Niek at the pull request. It seems the way to do the integration has changed since the switch from C to LUA. You also mentioned, you already have something cooking for shelly's. What would you suggest for me to deepen the topic?

Uli
 
Reply
#7
Yes, i'm using shelly for a few months myself succesfully. However, the implementation is currently too hacky to release. The good news is that i will be including them in the next release Smile

First i have to finish the MQTT implementation into pilight.
 
Reply
#8
(08-16-2019, 07:02 PM)curlymo Wrote: Yes, i'm using shelly for a few months myself succesfully. However, the implementation is currently too hacky to release. The good news is that i will be including them in the next release Smile

First i have to finish the MQTT implementation into pilight.

Sounds great. So I will be patient...

Uli
 
Reply
#9
(08-16-2019, 09:19 PM)Ulrich.Arnold Wrote:
(08-16-2019, 07:02 PM)curlymo Wrote: Yes, i'm using shelly for a few months myself succesfully. However, the implementation is currently too hacky to release. The good news is that i will be including them in the next release Smile

First i have to finish the MQTT implementation into pilight.

Sounds great. So I will be patient...

Uli

Hi curlymo

I try to connect my Shelly 2.5 shutter-controller with my php-hack. Works fine, but I have an issue with the generic screen. If I hit down and hit it a second time , I wanted to issue a stop-command. But the second hit does not get through at all. With the real 433 screen-protocoll this works fine

Uli
 
Reply
#10
That's probably because the first hit already sets the state of the device to up or down. The second hit is ignored because the status is already set.

Maybe you can build a rule that resets the status after each press.
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  re-recognition of device sending signals n0l0cale 1 503 02-21-2019, 12:30 PM
Last Post: TerryLewis

Forum Jump:


Browsing: 1 Guest(s)