Giter VIP home page Giter VIP logo

ha-shellies-discovery's Introduction

Shellies Discovery

GitHub Release GitHub All Releases hacs_badge Community Forum Buy me a coffee PayPal_Me

Screenshot

This script adds MQTT discovery support for Shellies in the Home Assistant.

Prerequisites

This script needs Home Assistant python_script component so, if you never used it, I strongly suggest you to follow the official instruction and check that python_script is properly configured and it's working.

Installation

You can install this script via HACS or just download shellies_discovery.py file and save it in <config>/python_scripts folder.

After installing the script and adding automations, run Shellies Announce automation or restart Home Assistant twice.

Go to HA community for support and help.

Supported devices

  • Shelly 1 (with external sensors and external switch)
  • Shelly 1L (with external sensors)
  • Shelly 1PM (with external sensors)
  • Shelly 2 (relays and roller mode)
  • Shelly 2.5 (relays and roller mode)
  • Shelly 3EM
  • Shelly 4Pro
  • Shelly Air
  • Shelly Bulb
  • Shelly Bulb RGBW
  • Shelly Button1
  • Shelly Dimmer
  • Shelly Dimmer 2
  • Shelly Door/Window
  • Shelly Door/Window 2
  • Shelly DUO
  • Shelly EM
  • Shelly Flood
  • Shelly Gas
  • Shelly H&T (with or without USB adapter)
  • Shelly i3
  • Shelly Plug
  • Shelly Plug S
  • Shelly Plug US
  • Shelly RGBW2 (color and white mode)
  • Shelly Sense
  • Shelly Smoke
  • Shelly Vintage
  • Shelly UNI (with external sensors)
  • Shelly Motion

How to debug

To debug the script add this to your logger configuration:

# configuration.yaml file
logger:
  default: warning
  logs:
    homeassistant.components.python_script: debug
    homeassistant.components.automation: info

Troubleshooting checklist

  • correct MQTT configuration in Home Assistant with discovery enabled
  • same discovery_prefix in Home Assistant configuration and in script configuration
  • Shellies firmware updated to current version
  • Home Assistant updated to current version
  • enabled MQTT in Shellies configuration
  • you can't manually run the shellies_discovery.py script ('trigger' is undefined error)

Shelly device name

The script supports Shelly devices with non-standard names (Internet & Security -> Advanced - developer settings -> Custom MQTT prefix in the Shelly WWW panel). If you want to change the name of the Shelly device, you must first remove the device from Home Assistant (Configuration -> Integrations -> MQTT -> Device -> Remove). Otherwise, all device entities will be duplicated.

Minimal configuration

# configuration.yaml file
python_script:

# automations.yaml file
- id: shellies_announce
  alias: 'Shellies Announce'
  trigger:
    - platform: homeassistant
      event: start
    - platform: time_pattern
      hours: "/1"
  action:
    service: mqtt.publish
    data:
      topic: shellies/command
      payload: announce

- id: 'shellies_discovery'
  alias: 'Shellies Discovery'
  mode: queued
  max: 999
  trigger:
    platform: mqtt
    topic: shellies/announce
  action:
    service: python_script.shellies_discovery
    data_template:
      id: '{{ trigger.payload_json.id }}'
      mac: '{{ trigger.payload_json.mac }}'
      fw_ver: '{{ trigger.payload_json.fw_ver }}'
      model: '{{ trigger.payload_json.model }}'

Custom configuration example

# configuration.yaml file
python_script:

# automations.yaml file
- id: shellies_announce
  alias: 'Shellies Announce'
  trigger:
    - platform: homeassistant
      event: start
    - platform: time_pattern
      hours: "/1"
  action:
    service: mqtt.publish
    data:
      topic: shellies/command
      payload: announce

- id: 'shellies_discovery'
  alias: 'Shellies Discovery'
  mode: queued
  max: 999
  trigger:
    platform: mqtt
    topic: shellies/announce
  action:
    service: python_script.shellies_discovery
    data_template:
      id: '{{ trigger.payload_json.id }}'
      mac: '{{ trigger.payload_json.mac }}'
      fw_ver: '{{ trigger.payload_json.fw_ver }}'
      model: '{{ trigger.payload_json.model }}'
      discovery_prefix: 'hass'
      qos: 2
      shelly1-AABB9900:
        relay-0: "light"
        ext-temperature-0: true
        ext-temperature-1: true
        ext-temperature-2: true
        force_update_sensors: true
        ext-switch: true
      shelly1pm-aabb9911:
        ext-temperature-0: true
        ext-humidity-0: true
        push_off_delay: false
        force_update_sensors: true
      shelly1l-ddbb9911:
        ext-temperature-0: true
        ext-temperature-1: true
        ext-temperature-2: true
        ext-humidity-0: true
      shellyswitch-123409FF:
        relay-0: "fan"
        relay-0-name: "Bathroom Fan"
        relay-1: "light"
        relay-1-name: "Livingroom Light"
      shellyswitch-123409cc:
        relay-1: "fan"
      shellydimmer-883409cc:
        light-0-name: "Bedroom Lamp"
      shellyswitch25-334455AA:
        mode: "roller"
        roller-0-name: "Garage"
        roller-0-class: "garage"
        position_template: "{{ '{% if value | float < 30 %}0{% else %}{{ value }}{% endif %}' }}"
        set_position_template: "{{ '{%if position | float < 30 %}0{% else %}{{ position }}{% endif %}' }}"
      shellyplug-s-CCBBCCAA:
        relay-0: "light"
        force_update_sensors: true
      shellyht-11AA00CCDD:
        force_update_sensors: true
        expire_after: 500
      shellyht-11AA00CCEE:
        powered: "battery"
      shellyht-11AA00CCFF:
        powered: "ac"
      shellyrgbw2-AA123FF32:
        mode: "white"
        light-1-name: "Living room"
        light-2-name: "Bedroom"
        light-3-name: "Kitchen"
      shellyrgbw2-AA123FF84:
        mode: "rgbw"
      shellyem-BB23CC45:
        force_update_sensors: true
      ignored_devices:
        - shelly1-DD0011
        - shellyem-EECC22

Battery powered devices

For battery powered devices, the script requires you to set the value of 12h for sleep_mode.period or to configure expire_after yourself.

Script arguments

key optional type default description
discovery_prefix True string homeassistant MQTT discovery prefix
qos True integer 0 MQTT QoS, you can use 0, 1 or 2
ignored_devices True list None list of devices to ignore

Device arguments

key optional type default possible values description
relay-<NUM> True string switch switch, light, fan component to use with the relay number NUM
relay-<NUM>-name True string None string friendly name of the relay number NUM
roller-<NUM>-name True string None string friendly name of the roller number NUM
roller-<NUM>-class True string None string device_class of the roller number NUM
light-<NUM>-name True string None string friendly name of the light number NUM
ext-temperature-<NUM> True boolean false true, false presence of temperature sensor number NUM
ext-humidity-<NUM> True boolean false true, false presence of humidity sensor number NUM
ext-switch True boolean false true, false presence of external switch
force_update_sensors True boolean false true, false force update for sensors
push_off_delay True boolean true true, false off delay (2 sec) for longpush/shortpush/double shortpush/triple shortpush binary sensors
mode True string white, rgbw, relay, roller white or rgbw for Shelly RGBW2, relay or roller for Shelly 2/Shelly 2.5
powered True string battery ac, battery ac or battery powered for Shelly H&T
expire_after True integer 51840 expire after for battery powered sensors in seconds

ha-shellies-discovery's People

Contributors

314eter avatar bieniu avatar cciprian5 avatar edo78 avatar notroblowe avatar palinf avatar playmobil42 avatar staff1703 avatar t3hk0d3 avatar thomasgermain avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.