Tim's blah blah blah

Cloudless Shelly Smart Plug

(Updated: )

Here I document how I integrated Shelly S smart plugs into my Home Assistant/IoT environment. Shelly S plugs are 12A/2500W plugs which might just be enough to run a washing machine on. Also, their small form factor and relatively low price make them attractive plugs for high-power appliances.

Update July 10: these plugs unfortunately don’t have enough capacity to support my washing machine, when it starts heating the plug relay drops out. Also the power rating is ambiguous, on the plug it shows 10A and 2500W (which would be either 250V or 11A), whereas on the box it shows 12A (which at 230V should be 2760W). In the web interface it lists 2500W as well, so I think they’re not really 12A.

  1. Connect to power
  2. Firmware update
    1. Connect to hotspot, navigate to 192.168.33.1
    2. Connect to Internet-enabled WiFi
    3. Find IP (e.g. on MikroTik /ip dhcp-server lease print, perhaps 172.16.10.201)
    4. Run firmware update
    5. Connect to final WiFi
  3. Configure 0. Find IP (e.g. on MikroTik /ip dhcp-server lease print)
    1. Set ‘Restore Last Mode’ as power on default
    2. Enable CoIoT
    3. Set SNTP to ``0.nl.pool.ntp.org`
  4. Configure router for static IP
    1. Add
    /ip dhcp-server lease add address=172.16.20.24 server=IoT_DHCP mac-address=8C:AA:B5:57:75:E0 comment="shelly-s-5775e0"
    /ip dns static add address=172.16.20.24 name="shelly-s-5775e0" place-before=0 ttl="01:00:00" comment="infrastructure"
    /ip dns static add address=172.16.20.24 name="shelly-s-5775e0.lan" place-before=0 ttl="01:00:00" comment="infrastructure"
    
    1. Reboot plug to get final IP
  5. Add integration in Home Assistant
    1. Rename appliance to something useful
    2. Add icons (mdi:washingmachine)
    3. Connect new sensors to automations
  6. Connect to influxdb/grafana backend via (HTTP API)[https://shelly-api-docs.shelly.cloud/#common-http-api]
    1. Using curl
    INFLUXDBURI="http://localhost:8086/write?db=smarthomev3&precision=s"
    
    # Construct influxdb query
    # Beware of jq bug in v1.6! Took me a while to figure out it wasn't me. 
    # Patch by manually fixing offset after checking for symptons. This should
    # self-solve with update of jq at some point.
    # Update 20210707: only fails with DST, need to use today's date
    # https://github.com/stedolan/jq/issues/1713
    OFFS=0
    DATESTR=$(date +%Y-%m-%d)T00:00:00Z
    # DATESTR=2018-01-01T00:00:00Z
    JQCHECKSTR=$(jq --arg DATESTR "$DATESTR" -nr '$DATESTR|fromdate|todate')
    if [[ "${JQCHECKSTR}" != "${DATESTR}" ]]; then OFFS=3600; fi
    
    
    
    if Ewattmin=$(curl --connect-timeout 5 --silent -X GET http://172.16.20.23/meter/0 | jq .total); then
        echo
    fi
    Ewattmin=$(curl --connect-timeout 5 --silent -X GET http://172.16.20.23/meter/0 | jq .total)
    Ejoule=$(( ${Ewattmin} * 60 ))
    uniqueid=$( curl -X GET http://172.16.20.23/shelly | jq -r .mac)
    curl --max-time 5 -i -XPOST ${INFLUXDBURI} --data-binary "energyv3,quantity=electricity,uniqueid=${uniqueid},type=consumption,source=washingmachine value=${Ejoule}"
    

#security #server #smarthome