ESPEasy on ShellyV1

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Sidey79
New user
Posts: 5
Joined: 03 Mar 2019, 16:02

ESPEasy on ShellyV1

#1 Post by Sidey79 » 03 Mar 2019, 16:19

Hi,

I've bought some Shelly V1 devices and flashed them with ESPEasy.


But i have some trouble, to get that work as i need:

First at all, i've connected a Switch (not a push button) on GPIO 5. The Switch should toggle the Relay which is connected at GPIO 4.
So GPIO 5 can be high or low which is not directly the same state on GPIO 4, because i also want to change the relay remote via FHEM .

I spent some times into the rules engine end now i have that, which doesn't do the job very well.

Problems so far with this rule:
If i boot the esp, GPIO 5 can be high or low, and if it is high it will trigger

Code: Select all

Button#Switch
which will switch the relay on.
This is not really what i want that lights are switched on, after a power loss.


I've configured a switch device as task #1, attatched to GPIO 5
I've configured a dummy decice as task #2 which should represent the state of the relay.
This doesn't work at all as i expect.


Code: Select all

on System#Boot do
   monitor,GPIO,4
   TaskValueSet 2,1,0
   TaskValueSet 1,1,0
endon

on Button#Switch do
   gpiotoggle,4
   TaskValueSet 2,1,[Button#Switch]
endon

on toggleRelay do
   gpiotoggle,4
   if [Button#Switch]=0
      TaskValueSet 1,1,1
   else
      TaskValueSet 1,1,0
endon

on GPIO,4 do
      TaskValueSet 2,1,%eventvalue%
endon

Code: Select all

{"System":{
"Build":20103,
"Git Build":"mega-20190216",
"System libraries":"ESP82xx Core 2_4_2, NONOS SDK 2.2.1(cfd48f3), LWIP: 2.0.3 PUYA support",
"Plugins":46,
"Plugin description":" [Normal]",
"Local time":"2019-03-03 15:12:29",
"Unit":3,
"Name":"ESP_ShellyV1_2",
"Uptime":33,
"Last boot cause":"Manual reboot",
"Reset Reason":"Software/System restart",
"Load":14.80,
"Load LC":8238,
"Free RAM":17800
},
"WiFi":{
"Hostname":"ESP-ShellyV1-2-3",
"IP config":"DHCP",
"IP":"10.2.11.58",
"Subnet Mask":"255.255.255.0",
"Gateway IP":"10.2.11.1",
"MAC address":"BC:DD:C2:94:17:BE",
"DNS 1":"10.2.11.1",
"DNS 2":"0.0.0.0",
"SSID":"xxxx",
"BSSID":"44:4E:6D:3B:10:8C",
"Channel":11,
"Connected msec":1967321,
"Last Disconnect Reason":1,
"Last Disconnect Reason str":"(1) Unspecified",
"Number reconnects":0,
"RSSI":-59
},
"Sensors":[
{
"TaskValues": [
{"ValueNumber":1,
"Name":"Switch",
"NrDecimals":0,
"Value":0
}],
"DataAcquisition": [
{"Controller":1,
"IDX":0,
"Enabled":"true"
},
{"Controller":2,
"IDX":0,
"Enabled":"false"
},
{"Controller":3,
"IDX":0,
"Enabled":"false"
}],
"TaskInterval":0,
"Type":"Switch input - Switch",
"TaskName":"Button",
"TaskEnabled":"true",
"TaskNumber":1
},
{
"TaskValues": [
{"ValueNumber":1,
"Name":"State",
"NrDecimals":0,
"Value":1
},
{"ValueNumber":2,
"Name":"",
"NrDecimals":2,
"Value":0.00
},
{"ValueNumber":3,
"Name":"",
"NrDecimals":2,
"Value":0.00
},
{"ValueNumber":4,
"Name":"",
"NrDecimals":2,
"Value":0.00
}],
"DataAcquisition": [
{"Controller":1,
"IDX":0,
"Enabled":"true"
},
{"Controller":2,
"IDX":0,
"Enabled":"false"
},
{"Controller":3,
"IDX":0,
"Enabled":"false"
}],
"TaskInterval":60,
"Type":"Generic - Dummy Device",
"TaskName":"Relay",
"TaskEnabled":"true",
"TaskNumber":2
},
{
"TaskValues": [
{"ValueNumber":1,
"Name":"uptime",
"NrDecimals":0,
"Value":30
},
{"ValueNumber":2,
"Name":"rssi",
"NrDecimals":2,
"Value":-58.00
},
{"ValueNumber":3,
"Name":"",
"NrDecimals":2,
"Value":0.00
},
{"ValueNumber":4,
"Name":"",
"NrDecimals":2,
"Value":0.00
}],
"DataAcquisition": [
{"Controller":1,
"IDX":0,
"Enabled":"true"
},
{"Controller":2,
"IDX":0,
"Enabled":"false"
},
{"Controller":3,
"IDX":0,
"Enabled":"false"
}],
"TaskInterval":600,
"Type":"Generic - System Info",
"TaskName":"SWITCH",
"TaskEnabled":"true",
"TaskNumber":3
}
],
"TTL":60000
}
I searched for some invertion command of a value, but didn't find anything in the docs. :(

May i'm on a complete wrong way how to solve my requiremens which are:

I want to be able to toggle locally (this works)
I want to be able to togge remote (this also works)
I want to be able to send a on or off comand from remote (currently this does not work)
I want to have the current state reported in a value which is reported to FHEM. (currently this does not work all the time)

Some hint's how to do that whould be nice.

Sidey

kimot
Normal user
Posts: 190
Joined: 12 Oct 2017, 20:46

Re: ESPEasy on ShellyV1

#2 Post by kimot » 03 Mar 2019, 22:13

I do not know FHEM, I am using Domoticz.
But You can create events "lamp_on" and lamp_off" which received from FHEM will switch relay.
And back report relay state to FHEM:

Some example with Domoticz:

Code: Select all

on lamp_on do    // this event from Domoticz will switch relay ON
    gpio,12,1
    gpio,13,0
endon

on lamp_off do      // this event from Domoticz will switch relay OFF
    gpio,12,0
    gpio,13,1
endon

on lamp_change do       // each press local button or incoming event " lamp_change" will change lamp state
  if [rele#Switch]=1      // if lamp was on, switch it off
    event,lamp_off
    SendToHTTP 192.168.1.253,8080,/json.htm?type=command&param=switchlight&idx=19&switchcmd=Off  // report current state to Domoticz for off
  else
    event,lamp_on     // else switch on
    SendToHTTP 192.168.1.253,8080,/json.htm?type=command&param=switchlight&idx=19&switchcmd=On   // report current state to Domoticz for on
  endif
endon

on SW01#Switch do      // each press of local switch will change lamp state
  event,lamp_change
endon

Sidey79
New user
Posts: 5
Joined: 03 Mar 2019, 16:02

Re: ESPEasy on ShellyV1

#3 Post by Sidey79 » 04 Mar 2019, 10:46

Thanks for your answert.

May you correct me. Ich think i started with something similar, but If you set a GPIO to 0 or 1 it will get a output pin and doesn't recognice anymore on level changes.

I figured out, that a pin can bei set to input_pullup with a GPIO value 2, but that doesn't really help.

kimot
Normal user
Posts: 190
Joined: 12 Oct 2017, 20:46

Re: ESPEasy on ShellyV1

#4 Post by kimot » 04 Mar 2019, 10:56

rele#Switch
is defined as input for the same gpio like relay ( gpio12 )

So this switch reflect actual state of relay and can be checked by if statement.
But I am using old v2.0-20180322 version.
Maybe in some "mega" versions this feature not works.
Something like this was mentioned in this forum for some versions, but I hoped it was
returned back to previous function.

WilliButz
New user
Posts: 5
Joined: 24 Feb 2016, 11:15

Re: ESPEasy on ShellyV1

#5 Post by WilliButz » 05 Mar 2019, 20:16

I have a working Shelly1 with fhem.
All your ‘requirements’ are working for me.

Important is a change to the ‘Switch-Input’.
https://github.com/letscontrolit/ESPEasy/issues/2112

After Version mega 20181130 it is not working.
May be they have put it back working.
See the Relaese Notes aof the build.
https://github.com/letscontrolit/ESPEas ... a-20181220

I use a Version mega-20181129

My setup:
Controller: FHEM HTTP Port 8383

Devices:
Switch input Switch
Name: Relais-1
GPIO-4 (D2)
Switch Type: Switch
Switch Button Type: Normal Switch
Debounce 0
Doubleclick: Disabled
Longpress: Disabled:
Send to Controller: Yes
Value: Relais-Status

Switch input Switch
Name: Switch-1
GPIO-5 (D1)
Switch Type: Switch
Switch Button Type: Normal Switch
Debounce 0
Doubleclick: Disabled
Longpress: Disabled:
Send to Controller: Yes
Value: Switch-Status

If the reaction to the switch is to slow, set in Tools/Advanced/Message Interval to 100ms
Or check high CPU load.

My Rule with light timer:

Code: Select all

// start switch Logik mit normal Switch Shelly1 
on Switch-1#Switch-Status=1 do
  if [Relais-1#Relais-Status]=1
    gpio,4,0
  else
    gpio,4,1
  endif
endon
//ende Switch-Relais Logik

// Morning on every day
on Clock#Time=All, 06:30 do
 if %systime% < %sunrise% //only before sunrise
  gpio,4,1
 endif
endon

// Morning off
on Clock#Time=All,%sunrise+5m% do
 if %systime% > 06:05 //my be everytime
   gpio,4,0
 endif
endon

TD-er
Core team member
Posts: 8644
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESPEasy on ShellyV1

#6 Post by TD-er » 06 Mar 2019, 12:09

Just as a remark, we have in the more recent builds an environment specially tailored for the Shelly-1.
It is the

Code: Select all

hard_core_250_Shelly_1_2M256
in PlatformIO.
At this moment the core 2.5.0 builds are excluded from the nightly builds since there were some issues with core 2.5.0, but you can make a version on your own, or have a look at the builds of about a month ago. (disabled core 2.5.0 on 20180211)

What this build offers:
- Support for 2MB flash with 256k SPIFFS, and thus room for OTA updates (not possible when using only 1 MB of the flash for the sketch)
- Reset to factory defaults option with the Shelly-1 as a pre-defined selection.

This last option does add basic rules and plugin configurations for the button and the switch in the Shelly-1.
So it will then pre-configure the right GPIO pins for the button and switch.

Sidey79
New user
Posts: 5
Joined: 03 Mar 2019, 16:02

Re: ESPEasy on ShellyV1

#7 Post by Sidey79 » 07 Mar 2019, 21:27

TD-er wrote: 06 Mar 2019, 12:09
What this build offers:
- Support for 2MB flash with 256k SPIFFS, and thus room for OTA updates (not possible when using only 1 MB of the flash for the sketch)
- Reset to factory defaults option with the Shelly-1 as a pre-defined selection.
This is a very nice and helpfull hint i think.
Is it impossible to update ota to such a version. Even not with the small ota 2 step image?

Sidey

TD-er
Core team member
Posts: 8644
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESPEasy on ShellyV1

#8 Post by TD-er » 12 Mar 2019, 22:54

Not entirely sure.
You will at least loose all settings, since the SPIFFS will be removed and thus newly created.

zyklop
New user
Posts: 1
Joined: 09 Sep 2017, 17:22

Re: ESPEasy on ShellyV1

#9 Post by zyklop » 09 Jul 2019, 22:01

@WilliButz

thanks for your great work !!!

I have a working Shelly1 with iobroker, huebridge and OpenHAB MQTT.
All my "requirements" are working fine now with "normal" switch !!
i only changed your script a little bit for toggling with normal Light Switch.

I use a Version mega-20190315 (Flashfile ESP_Easy_mega-20190315_normal_core_241_ESP8266_1M)

My setup:
Controller: OpenHAB MQTT Port 1883
(before configuring: GPIO 4 + 5 deleted in Hardware from I2C Interface)

Devices:
Switch input Switch
Name: Relay
GPIO-4 (D2)
Switch Type: Switch
Switch Button Type: Normal Switch
Debounce 0
Doubleclick: Disabled
Longpress: Disabled:
Send to Controller: Yes
Value: Relay

Switch input Switch
Name: Switch
GPIO-5 (D1)
Switch Type: Switch
Switch Button Type: Normal Switch
Debounce 0
Doubleclick: Disabled
Longpress: Disabled:
Send to Controller: Yes
Value: Switch


My Rules Set 1:

Code: Select all

//Beim Systemstart z.B. durch Stromausfall erstmal Verbraucher ausschalten !!
on System#Boot do
  gpio,4,0
  timerSet,1,10
endon

// start switch Logik mit normal Switch Shelly1 
on Switch#Switch=1 do
  if [Relay#Relay]=1
    gpio,4,0
  else
    gpio,4,1
  endif
endon
on Switch#Switch=0 do
  if [Relay#Relay]=0
    gpio,4,1
  else
    gpio,4,0
  endif
endon
//ende Switch-Relais Logik


It works like a charme !!!! :D

To read values of switch status i am looking to implement it with iobroker parser module. Works also fine for my enigma2 Receiver.
(Read status with URL: http://192.168.0.xxx/control?cmd=status,gpio,4 with results in json

log ""
plugin 1
pin 4
mode "output"
state 1


For toggling with alexa i use habridge on same machine with ip 127.0.0.1 and iobroker cloud adapter.

wish a nice day....

Sidey79
New user
Posts: 5
Joined: 03 Mar 2019, 16:02

Re: ESPEasy on ShellyV1

#10 Post by Sidey79 » 12 Oct 2019, 10:25

Hi,

Will there be any new version for the shelly available?

Haven't found anything like hard_core_250_Shelly_1_2M256
in the recent build.

Sidey

Post Reply

Who is online

Users browsing this forum: No registered users and 28 guests