Shelly Device Handlers for Hubitat

I wonder if it's not because it gets no readings. I don't remember getting warnings during the day when power production accrued. I'll check tomorrow.

I updated the driver. Now "Generic Component Energy Meter" child devices have thresholds to set.

With enabled logs you will still see device reports. But those that have smaller delta than threshold will not generate events.

If you want specifically check what was skipped, you can enable logs on the child device itself.

By default all thresholds are set to "0" giving the same default behavior.

1 Like

And the info flood stopped. Thank You again @dmitry.rozovik for Your work!!!

I noticed the dashboard shows no data on the Shelly 3 pm pro. Power meter nor energy meter.

Could you post logs from parent device and one of the child devices? (in case there are error)
And what threshold values are you using?

Hi

I've added Your driver to my Shelly Pro 4 PM V2 In usage I get a lot of excessive events.

Logs
dev:312023-05-22 12:18:33.838debugResponse: Connection : keep-alive

dev:312023-05-22 12:18:33.825debugResponse: Content-Length : 4

dev:312023-05-22 12:18:33.824debugResponse: Access-Control-Allow-Headers : *

dev:312023-05-22 12:18:33.822debugResponse: Access-Control-Allow-Origin : *

dev:312023-05-22 12:18:33.821debugResponse: Content-Type : application/json

dev:312023-05-22 12:18:33.819debugResponse: Server : Mongoose/6.18

dev:312023-05-22 12:18:32.574infoCheck Device FW

dev:312023-05-22 12:18:32.501debugSys Status called

dev:312023-05-22 12:18:32.434debugSys Status called

dev:312023-05-22 12:18:32.388debugWiFi Status called

dev:312023-05-22 12:18:32.387debugShelly Refresh called

dev:312023-05-22 12:18:30.346debugResponse: Connection : keep-alive

dev:312023-05-22 12:18:30.345debugResponse: Content-Length : 17

dev:312023-05-22 12:18:30.343debugResponse: Access-Control-Allow-Headers : *

dev:312023-05-22 12:18:30.342debugResponse: Access-Control-Allow-Origin : *

dev:312023-05-22 12:18:30.341debugResponse: Content-Type : application/json

dev:312023-05-22 12:18:30.339debugResponse: Server : Mongoose/6.18

dev:312023-05-22 12:18:30.287infoCalling /rpc/Switch.Set?id=0&on=true

dev:312023-05-22 12:18:30.286debugExecuting switch.on

dev:312023-05-22 12:18:23.848debugResponse: Connection : keep-alive

dev:312023-05-22 12:18:23.847debugResponse: Content-Length : 4

dev:312023-05-22 12:18:23.846debugResponse: Access-Control-Allow-Headers : *

dev:312023-05-22 12:18:23.844debugResponse: Access-Control-Allow-Origin : *

dev:312023-05-22 12:18:23.843debugResponse: Content-Type : application/json

dev:312023-05-22 12:18:23.842debugResponse: Server : Mongoose/6.18

dev:312023-05-22 12:18:22.351infoCheck Device FW

dev:312023-05-22 12:18:22.282debugSys Status called

dev:312023-05-22 12:18:22.226debugSys Status called

dev:312023-05-22 12:18:22.172debugWiFi Status called

dev:312023-05-22 12:18:22.171debugShelly Refresh called

dev:312023-05-22 12:18:20.135debugResponse: Connection : keep-alive

dev:312023-05-22 12:18:20.134debugResponse: Content-Length : 17

dev:312023-05-22 12:18:20.133debugResponse: Access-Control-Allow-Headers : *

dev:312023-05-22 12:18:20.132debugResponse: Access-Control-Allow-Origin : *

dev:312023-05-22 12:18:20.130debugResponse: Content-Type : application/json

dev:312023-05-22 12:18:20.129debugResponse: Server : Mongoose/6.18

dev:312023-05-22 12:18:20.069infoCalling /rpc/Switch.Set?id=0&on=true

dev:312023-05-22 12:18:20.068debugExecuting switch.on

Setings

Ok Sending logs

Parent

dev:322023-05-22 12:22:42.006info(null meter 1 Phase C) Meter generic report: Electric:voltage 229.8V

dev:322023-05-22 12:22:41.987info(null meter 1 Phase B) Meter generic report: Electric:voltage 237.1V

dev:322023-05-22 12:22:41.973info(null meter 1 Phase A) Meter generic report: Electric:voltage 235.9V

dev:322023-05-22 12:22:41.958info(null meter 1 Phase C) Meter generic report: Electric:powerFactor -1.0cos(φ)

dev:322023-05-22 12:22:41.945info(null meter 1 Phase B) Meter generic report: Electric:powerFactor -1.0cos(φ)

dev:322023-05-22 12:22:41.932info(null meter 1 Phase A) Meter generic report: Electric:powerFactor -1.0cos(φ)

dev:322023-05-22 12:22:41.919info(null meter 1 Total) Meter generic report: Electric:amperage 23.722A

dev:322023-05-22 12:22:41.906info(null meter 1 Phase C) Meter generic report: Electric:amperage 7.967A

dev:322023-05-22 12:22:41.894info(null meter 1 Phase B) Meter generic report: Electric:amperage 7.877A

dev:322023-05-22 12:22:41.881info(null meter 1 Phase A) Meter generic report: Electric:amperage 7.879A

dev:322023-05-22 12:22:41.866info(null meter 1 Total) Meter generic report: Electric:power 5546.142W

dev:322023-05-22 12:22:41.850info(null meter 1 Phase C) Meter generic report: Electric:power 1826.2W

dev:322023-05-22 12:22:41.832info(null meter 1 Phase B) Meter generic report: Electric:power 1865.3W

dev:322023-05-22 12:22:41.813info(null meter 1 Phase A) Meter generic report: Electric:power 1854.7W

dev:322023-05-22 12:22:41.809info([null meter 1 Phase A, null meter 1 Phase B, null meter 1 Phase C, null meter 1 Total]) parseShellyEnergyMeterStatus [a_act_power:1854.7, b_aprt_power:1867.6, b_act_power:1865.3, total_current:23.722, n_current:null, total_act_power:5546.142, a_voltage:235.9, c_current:7.967, b_current:7.877, a_current:7.879, b_voltage:237.1, a_aprt_power:1857.9, c_voltage:229.8, a_pf:-1.00, c_aprt_power:1829.6, total_aprt_power:5555.125, id:0, c_pf:-1.00, b_pf:-1.00, c_act_power:1826.2]

dev:322023-05-22 12:22:40.210infoparseShellyWifiStatus [rssi:0, sta_ip:null, ssid:null, status:connecting]

dev:322023-05-22 12:22:40.204infoNotifyEvent event [reason:201, component:wifi, event:sta_connect_fail, ts:1684750958.92]

dev:322023-05-22 12:22:38.978info(null meter 1 Phase C) Meter generic report: Electric:voltage 229.7V

dev:322023-05-22 12:22:38.965info(null meter 1 Phase B) Meter generic report: Electric:voltage 237.0V

dev:322023-05-22 12:22:38.952info(null meter 1 Phase A) Meter generic report: Electric:voltage 235.9V

dev:322023-05-22 12:22:38.938info(null meter 1 Phase C) Meter generic report: Electric:powerFactor -1.0cos(φ)

dev:322023-05-22 12:22:38.925info(null meter 1 Phase B) Meter generic report: Electric:powerFactor -1.0cos(φ)

dev:322023-05-22 12:22:38.912info(null meter 1 Phase A) Meter generic report: Electric:powerFactor -1.0cos(φ)

dev:322023-05-22 12:22:38.899info(null meter 1 Total) Meter generic report: Electric:amperage 23.77A

dev:322023-05-22 12:22:38.885info(null meter 1 Phase C) Meter generic report: Electric:amperage 7.983A

dev:322023-05-22 12:22:38.872info(null meter 1 Phase B) Meter generic report: Electric:amperage 7.894A

dev:322023-05-22 12:22:38.860info(null meter 1 Phase A) Meter generic report: Electric:amperage 7.893A

dev:322023-05-22 12:22:38.847info(null meter 1 Total) Meter generic report: Electric:power 5556.454W

dev:322023-05-22 12:22:38.833info(null meter 1 Phase C) Meter generic report: Electric:power 1829.1W

dev:322023-05-22 12:22:38.820info(null meter 1 Phase B) Meter generic report: Electric:power 1869.4W

dev:322023-05-22 12:22:38.807info(null meter 1 Phase A) Meter generic report: Electric:power 1858.0W

dev:322023-05-22 12:22:38.804info([null meter 1 Phase A, null meter 1 Phase B, null meter 1 Phase C, null meter 1 Total]) parseShellyEnergyMeterStatus [a_act_power:1858.0, b_aprt_power:1871.3, b_act_power:1869.4, total_current:23.770, n_current:null, total_act_power:5556.454, a_voltage:235.9, c_current:7.983, b_current:7.894, a_current:7.893, b_voltage:237.0, a_aprt_power:1861.4, c_voltage:229.7, a_pf:-1.00, c_aprt_power:1832.6, total_aprt_power:5565.286, id:0, c_pf:-1.00, b_pf:-1.00, c_act_power:1829.1]

Child TOTAL

dev:422023-05-22 12:27:24.874infoGeneric Component Energy Meter: amperage change is below threshold. Threshold 1 but delta is 0.22500090026855446; skipping event

dev:422023-05-22 12:27:24.820infoGeneric Component Energy Meter: power change is below threshold. Threshold 50 but delta is 6.3590429687501455; skipping event

dev:422023-05-22 12:27:21.875infoGeneric Component Energy Meter: amperage change is below threshold. Threshold 1 but delta is 0.22500090026855446; skipping event

dev:422023-05-22 12:27:21.820infoGeneric Component Energy Meter: power change is below threshold. Threshold 50 but delta is 6.3932226562501455; skipping event

dev:422023-05-22 12:27:18.874infoGeneric Component Energy Meter: amperage change is below threshold. Threshold 1 but delta is 0.1999993743896482; skipping event

dev:422023-05-22 12:27:18.820infoGeneric Component Energy Meter: power change is below threshold. Threshold 50 but delta is 12.465000000000146; skipping event

dev:422023-05-22 12:27:14.874infoGeneric Component Energy Meter: amperage change is below threshold. Threshold 1 but delta is 0.14799932861328102; skipping event

dev:422023-05-22 12:27:14.820infoGeneric Component Energy Meter: power change is below threshold. Threshold 50 but delta is 23.417148437500146; skipping event

dev:422023-05-22 12:27:11.874infoGeneric Component Energy Meter: amperage change is below threshold. Threshold 1 but delta is 0.1660008850097654; skipping event

dev:422023-05-22 12:27:11.819infoGeneric Component Energy Meter: power change is below threshold. Threshold 50 but delta is 17.395175781250146; skipping event

dev:422023-05-22 12:27:10.371infoGeneric Component Energy Meter: amperage change is below threshold. Threshold 1 but delta is 0.18400053405761696; skipping event

dev:422023-05-22 12:27:10.317infoGeneric Component Energy Meter: power change is below threshold. Threshold 50 but delta is 13.273105468750146; skipping event

dev:422023-05-22 12:27:10.166infoGeneric Component Energy Meter: amperage change is below threshold. Threshold 1 but delta is 0.24499945068359352; skipping event

dev:422023-05-22 12:27:10.112infoGeneric Component Energy Meter: power change is below threshold. Threshold 50 but delta is 2.0690039062501455; skipping event

dev:422023-05-22 12:27:02.149infoGeneric Component Energy Meter: amperage change is below threshold. Threshold 1 but delta is 0.38900045776367165; skipping event

dev:422023-05-22 12:27:02.096infoGeneric Component Energy Meter: power change is below threshold. Threshold 50 but delta is 33.258144531249854; skipping event

dev:422023-05-22 12:27:01.916infoElectric 145.94014kWh

dev:422023-05-22 12:26:58.877infoGeneric Component Energy Meter: amperage change is below threshold. Threshold 1 but delta is 0.355000061035156; skipping event

dev:422023-05-22 12:26:58.823infoGeneric Component Energy Meter: power change is below threshold. Threshold 50 but delta is 24.829921874999854; skipping event

dev:422023-05-22 12:26:55.877infoGeneric Component Energy Meter: amperage change is below threshold. Threshold 1 but delta is 0.21900038146972634; skipping event

dev:422023-05-22 12:26:55.824infoGeneric Component Energy Meter: power change is below threshold. Threshold 50 but delta is 4.8277929687501455; skipping event

dev:422023-05-22 12:26:52.878infoGeneric Component Energy Meter: amperage change is below threshold. Threshold 1 but delta is 0.10299925231933571; skipping event

dev:422023-05-22 12:26:52.824infoGeneric Component Energy Meter: power change is below threshold. Threshold 50 but delta is 34.503085937500146; skipping event

dev:422023-05-22 12:26:48.880infoGeneric Component Energy Meter: amperage change is below threshold. Threshold 1 but delta is 0.07300047302246071; skipping event

dev:422023-05-22 12:26:48.826infoGeneric Component Energy Meter: power change is below threshold. Threshold 50 but delta is 43.402011718750146; skipping event

dev:422023-05-22 12:26:45.883infoGeneric Component Energy Meter: amperage change is below threshold. Threshold 1 but delta is 0.15900091552734352; skipping event

dev:422023-05-22 12:26:45.828infoGeneric Component Energy Meter: power change is below threshold. Threshold 50 but delta is 21.532871093750146; skipping event

dev:422023-05-22 12:26:42.887infoGeneric Component Energy Meter: amperage change is below threshold. Threshold 1 but delta is 0.2559991302490232; skipping event

dev:422023-05-22 12:26:42.829infoElectric 5813.84W

So the child clearly says what happens

Generic Component Energy Meter: change is below threshold. Threshold 1 but delta is 0.21900038146972634; skipping event

Using this (child) log you can adjust thresholds to more resonable values to get event more or less often

For example, you can try to set amperage threshold to 0.2 or 0.3 (this should be close equivalent of 450 and 680 W of power). Right now you have 1.0 that is around 2.2..2.3 kW. So it will 'see' only a teapot or water heater like load change.

For voltage on phase child devices something in range 2..10V threshold should do. 'Total' will not report voltage is there is no such thing as total voltage for 3 phases). It just uses the same child device type (with voltage attribute/event).

Regarding 4PM. It also needs thresholds. I'm going to add them too.
It uses different child device type(s). Specifically 'switch' and 'window shutter' (for cover profile). Right now there are no thresholds.

1 Like

Regarding energy report. This one is a bit harder. Documentation says device reports energy once it stores accumulated measurements in the internal memory. And this seem to happen once per hour (if I get documentation correctly). It needs patient log analisys for related reports to check if they were handled correctly.

Hi,
Just setting up my new Shelly 1 and have the same settings per your screenshot above.

Could you tell me please how you got the "Contact" parameter displayed under the Current States?
I can seem to get this listed, l have the same settings and the same device driver version

Thanks in advance

I have a problem with refreshing the status of Shelly 2.5 Swtich.
When I hit the button 'ON' or 'OFF' in device command section current state is not refreshed automatically. I need to hit 'Refresh' to update the current state.

I use 'Shelly WiFi Switch' driver and each channel is 'Generic Component Metering Switch'.

What can I do?

Maybe this could help

1 Like

Thank you so much.
That helped for my Shelly 2.5 and Shelly 1 switches.

1 Like

Hello @dmitry.rozovik. I am trying to use a shelly 2PM as cover. First steps are ok, hubitat creates the child devices and one of then is a Generic Component Metered Window Shade that controls the device for open and close flawlessly. However, when I try to set position, it doesn't work and this log appears:


Could you please check what is happening?
tks

Sure. I'll heck the code.

Update:
Looks like a typo in function argument list in the childdevice code. Will update the code shortly.

Update:
Fresh driver uploaded. You dont need to reinstall the device. Driver/bundle import is enough (only code update is needed).

Update:

Added Shelly Wall Display support. Special thanks to @simon for remote testing changes and helping to debug the driver. It were rather a set of fixes as all the required functionality were already inplace.

Supports temperature, humidity and luminance sensors as well as single switch and single input components.

Thinking on adding BLE gateway functionality (as Pro devices have ability to work as a BLE gateway):
For this to work a gateway will have to use local driver/translator script to send events trough the Hubitat Shelly driver. The event listening part is already in. But implemented as a simple string data packets. It is quite easy to add event type to pass child device attribute change. The only queston for now is about the best way to spawn child devices to handle BLE-parser-script generated events. Currently my head spins around some sort of handshake event sent at the shelly device boot (or rather translator-script start) that will ask/announce child devices it wants to send events to. And hubitat side driver will check and spawn those if they are missing. Basically a 'virtual component' device will be requested from withing shelly script to avoid constant driver changes each time when adding new BLE device type.

Not something to be seen soon as I have no BLE sensor device to test and develop on. It needs two side (hubitat api and shelly script) code changes to work on.

2 Likes

Shelly will be adding Room Thermometer support to the Wall Display in the coming weeks. Also an updated version of the wall display that will not require a negative power line..... Also webhooks that should allow us to trigger events on our hubs.

So I'm looking forward to these features, as I want to use Wall Displays in place of old Z-Wave battery operated room thermostats - getting them to send events to HE for my routines to fire on/off the heating.

Many thanks @dmitry.rozovik for the driver, works great and I look forward to assisting you in getting the new features operable when they arrive.

This driver already has ability to catch custom events from script within device it self.

To make it work a one (or more) script slot needs to be preallocated. Then after pressing 'configure' special switch-like child devices will be spawned for each script slot. The hold an event attribute to show last catched event. Devices them selves allow to start/stop scripts trough on/off commands (so the can be placed as tiles on dashbords).

Then shelly scipt can be written inside script slot. Here is an example of sending event (it can be found in the driver as a sample; but it is ill formatted on the device page so it is not so easy to read from there):

// Use this script to test driver-ShellyScript interation (and as a base)
// Script child devices appear after creating script and 'configuring' driver afterwards
// Note that 'Configure' will re-creare all child devices. So dashboards and rules have to be readjusted afterwards if were previously set!

let alertTimer = null;
let eventCount = 0;

function startTimer() {
  // 1S step is extremely aggressive for Hubitat. Set only for debugging/testing!
  let timeStep = 1 * 1000; // 1S
  alertTimer = Timer.set(timeStep, true, function (userData) {
    ++eventCount;
    // Would be nice to use restricted event name 'variable'. 
    // This will distinguish internal events and events adressed to the Hubitat hub

    // data can be of any JSON type. But will be passed as String
    Shelly.emitEvent("variable", eventCount); // This will be sent to the child script device attribute
  }, null/*userData*/ );
}

startTimer()

The main difference comparing to webhooks (aside of the ability to customize event contents and conditions) is that webhooks require opening inbound requests/connections to the hub while websocket stream events does not (as this stream is open/initiated from hub to device; it will just work).

1 Like

Could it be your driver is not working when the device is password protected?

It is possible. But it should. There were some mentions about changes in firmware changelog regarding passwords. Driver implements digest authtentification. On 0.14 it worked. I'll test on 1.0.3.

Logs should show what happens in advance.

Just checked on Pro 2PM:
After setting device passworg:

dev:4772023-09-20 21:37:34.121errorUnauthorized HTTP query. Please, check your password.

After setting same password on the driver side (upside down order):

dev:4772023-09-20 21:38:10.079info(Boiler (bathroom) script 3) Script running false
dev:4772023-09-20 21:38:10.033debug(Boiler (bathroom) script 3) parseShellyScriptStatus [id:3, running:false, mem_free:24108]
dev:4772023-09-20 21:38:10.029info(Boiler (bathroom) script 2) Script running true
dev:4772023-09-20 21:38:10.000debug(Boiler (bathroom) script 2) parseShellyScriptStatus [id:2, running:true, mem_used:1092, mem_peak:1610, mem_free:24108]
dev:4772023-09-20 21:38:09.996info(Boiler (bathroom) script 1) Script running false
dev:4772023-09-20 21:38:09.958debug(Boiler (bathroom) script 1) parseShellyScriptStatus [id:1, running:false, mem_free:24108]
dev:4772023-09-20 21:38:09.954debug(Boiler (bathroom) input 2) parseShellyCommonStatus [id:1, state:false]
dev:4772023-09-20 21:38:09.936info(Boiler (bathroom) input 2) Input state false
dev:4772023-09-20 21:38:09.908debug(Boiler (bathroom) input 2) parseShellyInputStatus [id:1, state:false]
dev:4772023-09-20 21:38:09.903debug(Boiler (bathroom) input 1) parseShellyCommonStatus [id:0, state:null]
dev:4772023-09-20 21:38:09.850debug(Boiler (bathroom) input 1) parseShellyInputStatus [id:0, state:null]
dev:4772023-09-20 21:38:09.847debugparseShellyEthernetStatus [ip:null]
dev:4772023-09-20 21:38:09.843debugparseShellyCloudStatus [connected:false]
dev:4772023-09-20 21:38:09.839debugHTTP Async Response: [id:112, auth:Digest] ::: [ble:[:], cloud:[connected:false], eth:[ip:null], input:0:[id:0, state:null], input:1:[id:1, state:false], mqtt:[connected:false], script:1:[id:1, running:false, mem_free:24108], script:2:[id:2, running:true, mem_used:1092, mem_peak:1610, mem_free:24108], script:3:[id:3, running:false, mem_free:24108], switch:0:[id:0, source:init, output:false, apower:0.0, voltage:1.6, freq:50.1, current:0.000, pf:0.00, aenergy:[total:0.000, by_minute:[0.000, 0.000, 0.000], minute_ts:1695235090], temperature:[tC:30.9, tF:87.6]], switch:1:[id:1, source:init, output:false, apower:0.0, voltage:1.8, freq:50.1, current:0.000, pf:0.00, aenergy:[total:0.000, by_minute:[0.000, 0.000, 0.000], minute_ts:1695235090], temperature:[tC:31.5, tF:88.8]], sys:[mac:EC62608DC75C, restart_required:false, time:21:38, unixtime:1695235091, uptime:22017, ram_size:243156, ram_free:138424, fs_size:524288, fs_free:188416, cfg_rev:60, kvs_rev:4, schedule_rev:2, webhook_rev:0, available_updates:[:]], wifi:[sta_ip:192.168.1.197, status:got ip, ssid:Linksys07064, rssi:-68], ws:[connected:false]]
dev:4772023-09-20 21:38:09.693infoHTTP authtentification sequence...
dev:4772023-09-20 21:38:09.273debugHTTP Async query: Shelly.GetStatus([:])
1 Like