Shellies Discovery Script

Cattura1

- id: shellies_discovery
  alias: "Shellies Discovery"
  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 }}"
      qos: 1
      shellyht-119912AA: "ac_power"
homeassistant/sensor/shellyht-119912AA-temperature/config {"name":"Shelly H&T 119912AA Temperature","stat_t":"~sensor/temperature","unit_of_meas":"°C","dev_cla":"temperature","val_tpl":"{{value|float|round(1)}}","exp_aft":"7200","uniq_id":"shellyht-119912AA-temperature","qos":"1","dev": {"ids": ["11990099"],"name":"Shelly H&T 119912AA","mdl":"Shelly H&T","sw":"20190402-134544/v1.5.1@9be72c7e","mf":"Allterco Robotics"},"~":"shellies/shellyht-119912AA/"}
homeassistant/sensor/shellyht-119912AA-humidity/config {"name":"Shelly H&T 119912AA Humidity","stat_t":"~sensor/humidity","unit_of_meas":"%","dev_cla":"humidity","val_tpl":"{{value|float|round(1)}}","exp_aft":"7200","uniq_id":"shellyht-119912AA-humidity","qos":"1","dev": {"ids": ["11990099"],"name":"Shelly H&T 119912AA","mdl":"Shelly H&T","sw":"20190402-134544/v1.5.1@9be72c7e","mf":"Allterco Robotics"},"~":"shellies/shellyht-119912AA/"}
homeassistant/sensor/shellyht-119912AA-battery/config (null)

Hi,

Thanks for great work,

I had a problem with my RGBW2 shelly. It is switched in white mode but it failed to add 4 white light channels, only color light was added. It tried to add white ones but with empty config - it looks that it never entered if statement designed for rgbw2:

   1137     config_light = data.get(id, data.get(id.lower(), ATTR_RGBW))
   1138     if config_light == ATTR_WHITE and model == ATTR_MODEL_SHELLYRGBW2:

config_light is returned as rgbw here.

For test purposes I changed it manually to ATTR_RGBW in if statement but I’m not sure if it breaks something in entire script or not. Lights were created after this test. Also, I didn’t get power consumption elements for those channels.

This is what is send to mqtt:

shellies/shellyrgbw2-<<DEVICE-ID>>/white/0 off
shellies/shellyrgbw2-<<DEVICE-ID>>/white/0/status {"ison":false,"has_timer":false,"timer_remaining":0,"mode":"white","brightness":0,"power":0.00,"overpower":false}
shellies/shellyrgbw2-<<DEVICE-ID>>/white/1 off
shellies/shellyrgbw2-<<DEVICE-ID>>/white/1/status {"ison":false,"has_timer":false,"timer_remaining":0,"mode":"white","brightness":1,"power":0.00,"overpower":false}
shellies/shellyrgbw2-<<DEVICE-ID>>/white/2 on
shellies/shellyrgbw2-<<DEVICE-ID>>/white/2/status {"ison":true,"has_timer":false,"timer_remaining":0,"mode":"white","brightness":100,"power":13.91,"overpower":false}
shellies/shellyrgbw2-<<DEVICE-ID>>/white/3 on
shellies/shellyrgbw2-<<DEVICE-ID>>/white/3/status {"ison":true,"has_timer":false,"timer_remaining":0,"mode":"white","brightness":52,"power":7.23,"overpower":false}

Everything looks good to me:

homedevelop/light/shellyrgbw2-AABB22-0/config (null)
homedevelop/binary_sensor/shellyrgbw2-AABB22-color-overpower-0/config (null)
homedevelop/binary_sensor/shellyrgbw2-AABB22-input-0/config (null)
homedevelop/binary_sensor/shellyrgbw2-AABB22-color-input-0/config (null)
homedevelop/sensor/shellyrgbw2-AABB22-color-power-0/config (null)
homedevelop/light/shellyrgbw2-AABB22-white-0/config {"schema":"template","name":"Shelly RGBW2 AABB22 Light 0","cmd_t":"~white/0/set","stat_t":"~white/0/status","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","cmd_on_tpl":"{\"turn\":\"on\"{% if brightness is defined %},\"brightness\":{{brightness|float|multiply(0.3922)|round}}{% endif %}{% if white_value is defined %},\"white\":{{white_value}}{% endif %}{% if effect is defined %},\"effect\":{{effect}}{% endif %}}","cmd_off_tpl":"{\"turn\":\"off\"}","stat_tpl":"{% if value_json.ison %}on{% else %}off{% endif %}","bri_tpl":"{{value_json.brightness|float|multiply(2.55)|round}}","uniq_id":"shellyrgbw2-AABB22-light-white-0","qos":"0","dev": {"ids": ["11F3EB445566"],"name":"Shelly RGBW2 AABB22","mdl":"Shelly RGBW2","sw":"20190711-084053/v1.5.0-hotfix4@3b4f7414","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-AABB22/"}
homedevelop/binary_sensor/shellyrgbw2-AABB22-white-overpower-0/config {"name":"Shelly RGBW2 AABB22 Overpower 0","stat_t":"~white/0/status","val_tpl":"{% if value_json.overpower == true %}ON{% else %}OFF{% endif %}","dev_cla":"power","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyrgbw2-AABB22-white-overpower-0","qos":"0","dev": {"ids": ["11F3EB445566"],"name":"Shelly RGBW2 AABB22","mdl":"Shelly RGBW2","sw":"20190711-084053/v1.5.0-hotfix4@3b4f7414","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-AABB22/"}
homedevelop/binary_sensor/shellyrgbw2-AABB22-input-0/config (null)
homedevelop/binary_sensor/shellyrgbw2-AABB22-white-input-0/config {"name":"Shelly RGBW2 AABB22 Input 0","stat_t":"~input/0","pl_on":"1","pl_off":"0","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyrgbw2-AABB22-white-input-0","qos":"0","dev": {"ids": ["11F3EB445566"],"name":"Shelly RGBW2 AABB22","mdl":"Shelly RGBW2","sw":"20190711-084053/v1.5.0-hotfix4@3b4f7414","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-AABB22/"}
homedevelop/sensor/shellyrgbw2-AABB22-white-power-0/config {"name":"Shelly RGBW2 AABB22 Power 0","stat_t":"~white/0/status","unit_of_meas":"W","dev_cla":"power","val_tpl":"{{value_json.power|float|round(1)}}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyrgbw2-AABB22-white-power-0","qos":"0","dev": {"ids": ["11F3EB445566"],"name":"Shelly RGBW2 AABB22","mdl":"Shelly RGBW2","sw":"20190711-084053/v1.5.0-hotfix4@3b4f7414","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-AABB22/"}
homedevelop/light/shellyrgbw2-AABB22-white-1/config {"schema":"template","name":"Shelly RGBW2 AABB22 Light 1","cmd_t":"~white/1/set","stat_t":"~white/1/status","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","cmd_on_tpl":"{\"turn\":\"on\"{% if brightness is defined %},\"brightness\":{{brightness|float|multiply(0.3922)|round}}{% endif %}{% if white_value is defined %},\"white\":{{white_value}}{% endif %}{% if effect is defined %},\"effect\":{{effect}}{% endif %}}","cmd_off_tpl":"{\"turn\":\"off\"}","stat_tpl":"{% if value_json.ison %}on{% else %}off{% endif %}","bri_tpl":"{{value_json.brightness|float|multiply(2.55)|round}}","uniq_id":"shellyrgbw2-AABB22-light-white-1","qos":"0","dev": {"ids": ["11F3EB445566"],"name":"Shelly RGBW2 AABB22","mdl":"Shelly RGBW2","sw":"20190711-084053/v1.5.0-hotfix4@3b4f7414","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-AABB22/"}
homedevelop/binary_sensor/shellyrgbw2-AABB22-white-overpower-1/config {"name":"Shelly RGBW2 AABB22 Overpower 1","stat_t":"~white/1/status","val_tpl":"{% if value_json.overpower == true %}ON{% else %}OFF{% endif %}","dev_cla":"power","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyrgbw2-AABB22-white-overpower-1","qos":"0","dev": {"ids": ["11F3EB445566"],"name":"Shelly RGBW2 AABB22","mdl":"Shelly RGBW2","sw":"20190711-084053/v1.5.0-hotfix4@3b4f7414","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-AABB22/"}
homedevelop/sensor/shellyrgbw2-AABB22-white-power-1/config {"name":"Shelly RGBW2 AABB22 Power 1","stat_t":"~white/1/status","unit_of_meas":"W","dev_cla":"power","val_tpl":"{{value_json.power|float|round(1)}}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyrgbw2-AABB22-white-power-1","qos":"0","dev": {"ids": ["11F3EB445566"],"name":"Shelly RGBW2 AABB22","mdl":"Shelly RGBW2","sw":"20190711-084053/v1.5.0-hotfix4@3b4f7414","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-AABB22/"}
homedevelop/light/shellyrgbw2-AABB22-white-2/config {"schema":"template","name":"Shelly RGBW2 AABB22 Light 2","cmd_t":"~white/2/set","stat_t":"~white/2/status","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","cmd_on_tpl":"{\"turn\":\"on\"{% if brightness is defined %},\"brightness\":{{brightness|float|multiply(0.3922)|round}}{% endif %}{% if white_value is defined %},\"white\":{{white_value}}{% endif %}{% if effect is defined %},\"effect\":{{effect}}{% endif %}}","cmd_off_tpl":"{\"turn\":\"off\"}","stat_tpl":"{% if value_json.ison %}on{% else %}off{% endif %}","bri_tpl":"{{value_json.brightness|float|multiply(2.55)|round}}","uniq_id":"shellyrgbw2-AABB22-light-white-2","qos":"0","dev": {"ids": ["11F3EB445566"],"name":"Shelly RGBW2 AABB22","mdl":"Shelly RGBW2","sw":"20190711-084053/v1.5.0-hotfix4@3b4f7414","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-AABB22/"}
homedevelop/binary_sensor/shellyrgbw2-AABB22-white-overpower-2/config {"name":"Shelly RGBW2 AABB22 Overpower 2","stat_t":"~white/2/status","val_tpl":"{% if value_json.overpower == true %}ON{% else %}OFF{% endif %}","dev_cla":"power","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyrgbw2-AABB22-white-overpower-2","qos":"0","dev": {"ids": ["11F3EB445566"],"name":"Shelly RGBW2 AABB22","mdl":"Shelly RGBW2","sw":"20190711-084053/v1.5.0-hotfix4@3b4f7414","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-AABB22/"}
homedevelop/sensor/shellyrgbw2-AABB22-white-power-2/config {"name":"Shelly RGBW2 AABB22 Power 2","stat_t":"~white/2/status","unit_of_meas":"W","dev_cla":"power","val_tpl":"{{value_json.power|float|round(1)}}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyrgbw2-AABB22-white-power-2","qos":"0","dev": {"ids": ["11F3EB445566"],"name":"Shelly RGBW2 AABB22","mdl":"Shelly RGBW2","sw":"20190711-084053/v1.5.0-hotfix4@3b4f7414","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-AABB22/"}
homedevelop/light/shellyrgbw2-AABB22-white-3/config {"schema":"template","name":"Shelly RGBW2 AABB22 Light 3","cmd_t":"~white/3/set","stat_t":"~white/3/status","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","cmd_on_tpl":"{\"turn\":\"on\"{% if brightness is defined %},\"brightness\":{{brightness|float|multiply(0.3922)|round}}{% endif %}{% if white_value is defined %},\"white\":{{white_value}}{% endif %}{% if effect is defined %},\"effect\":{{effect}}{% endif %}}","cmd_off_tpl":"{\"turn\":\"off\"}","stat_tpl":"{% if value_json.ison %}on{% else %}off{% endif %}","bri_tpl":"{{value_json.brightness|float|multiply(2.55)|round}}","uniq_id":"shellyrgbw2-AABB22-light-white-3","qos":"0","dev": {"ids": ["11F3EB445566"],"name":"Shelly RGBW2 AABB22","mdl":"Shelly RGBW2","sw":"20190711-084053/v1.5.0-hotfix4@3b4f7414","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-AABB22/"}
homedevelop/binary_sensor/shellyrgbw2-AABB22-white-overpower-3/config {"name":"Shelly RGBW2 AABB22 Overpower 3","stat_t":"~white/3/status","val_tpl":"{% if value_json.overpower == true %}ON{% else %}OFF{% endif %}","dev_cla":"power","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyrgbw2-AABB22-white-overpower-3","qos":"0","dev": {"ids": ["11F3EB445566"],"name":"Shelly RGBW2 AABB22","mdl":"Shelly RGBW2","sw":"20190711-084053/v1.5.0-hotfix4@3b4f7414","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-AABB22/"}
homedevelop/sensor/shellyrgbw2-AABB22-white-power-3/config {"name":"Shelly RGBW2 AABB22 Power 3","stat_t":"~white/3/status","unit_of_meas":"W","dev_cla":"power","val_tpl":"{{value_json.power|float|round(1)}}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyrgbw2-AABB22-white-power-3","qos":"0","dev": {"ids": ["11F3EB445566"],"name":"Shelly RGBW2 AABB22","mdl":"Shelly RGBW2","sw":"20190711-084053/v1.5.0-hotfix4@3b4f7414","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-AABB22/"}

Please show me your configuration and debug log for python_script component.

Config:

default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
http:
  server_port: 8123
  ssl_certificate: "***"
  ssl_key: "***"
  ip_ban_enabled: true
  login_attempts_threshold: 5
  base_url: ***

tts:
  - platform: google_translate

mqtt:
  broker: ***
  port: 1883
  username: "***"
  password: "***"
  discovery: true
  discovery_prefix: homeassistant

python_script:

logger:
  default: info
  logs:
    pydeconz: debug
    homeassistant.components.deconz: debug
    homeassistant.components.python_script: debug


group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

This is what I get from debug logs from script:

2020-04-27 23:29:45 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/light/shellyrgbw2-<<DEVICE-ID>>-0/config {"schema":"template","name":"Shelly RGBW2 <<DEVICE-ID>> Light 0","cmd_t":"~color/0/set","stat_t":"~color/0/status","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","fx_list":["Off", "Meteor Shower", "Gradual Change", "Flash"],"cmd_on_tpl":"{\"turn\":\"on\"{% if brightness is defined %},\"gain\":{{brightness|float|multiply(0.3922)|round}}{% endif %}{% if red is defined and green is defined and blue is defined %},\"red\":{{red}},\"green\":{{green}},\"blue\":{{blue}}{% endif %}{% if white_value is defined %},\"white\":{{white_value}}{% endif %}{% if effect is defined %}{% if effect == \"Meteor Shower\" %}\"effect\":1{% elif effect == \"Gradual Change\" %}\"effect\":2{% elif effect == \"Flash\" %}\"effect\":3{% else %}\"effect\":0{% endif %}{% else %}\"effect\":0{% endif %}}","cmd_off_tpl":"{\"turn\":\"off\"}","stat_tpl":"{% if value_json.ison %}on{% else %}off{% endif %}","bri_tpl":"{{value_json.gain|float|multiply(2.55)|round}}","r_tpl":"{{value_json.red}}","g_tpl":"{{value_json.green}}","b_tpl":"{{value_json.blue}}","whit_val_tpl":"{{value_json.white}}","fx_tpl":"{% if value_json.effect == 1 %}Meteor Shower{% elif value_json.effect == 2 %}Gradual Change{% elif value_json.effect == 3 %}Flash{% else %}Off{% endif %}","uniq_id":"shellyrgbw2-<<DEVICE-ID>>-light-0","qos":"0","dev": {"ids": ["ECFABC<<DEVICE-ID>>"],"name":"Shelly RGBW2 <<DEVICE-ID>>","mdl":"Shelly RGBW2","sw":"20200309-104453/v1.6.0@43056d58","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-<<DEVICE-ID>>/"}
2020-04-27 23:29:46 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/binary_sensor/shellyrgbw2-<<DEVICE-ID>>-color-overpower-0/config {"name":"Shelly RGBW2 <<DEVICE-ID>> Overpower 0","stat_t":"~color/0/status","val_tpl":"{% if value_json.overpower == true %}ON{% else %}OFF{% endif %}","avty_t":"~online","dev_cla":"power","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyrgbw2-<<DEVICE-ID>>-color-overpower-0","qos":"0","dev": {"ids": ["ECFABC<<DEVICE-ID>>"],"name":"Shelly RGBW2 <<DEVICE-ID>>","mdl":"Shelly RGBW2","sw":"20200309-104453/v1.6.0@43056d58","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-<<DEVICE-ID>>/"}
2020-04-27 23:29:46 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/binary_sensor/shellyrgbw2-<<DEVICE-ID>>-input-0/config
2020-04-27 23:29:47 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/binary_sensor/shellyrgbw2-<<DEVICE-ID>>-color-input-0/config {"name":"Shelly RGBW2 <<DEVICE-ID>> Input 0","stat_t":"~input/0","pl_on":"1","pl_off":"0","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyrgbw2-<<DEVICE-ID>>-color-input-0","qos":"0","dev": {"ids": ["ECFABC<<DEVICE-ID>>"],"name":"Shelly RGBW2 <<DEVICE-ID>>","mdl":"Shelly RGBW2","sw":"20200309-104453/v1.6.0@43056d58","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-<<DEVICE-ID>>/"}
2020-04-27 23:29:47 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/sensor/shellyrgbw2-<<DEVICE-ID>>-color-power-0/config {"name":"Shelly RGBW2 <<DEVICE-ID>> Power 0","stat_t":"~color/0/status","unit_of_meas":"W","dev_cla":"power","val_tpl":"{{value_json.power|float|round(1)}}","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","uniq_id":"shellyrgbw2-<<DEVICE-ID>>-color-power-0","qos":"0","dev": {"ids": ["ECFABC<<DEVICE-ID>>"],"name":"Shelly RGBW2 <<DEVICE-ID>>","mdl":"Shelly RGBW2","sw":"20200309-104453/v1.6.0@43056d58","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-<<DEVICE-ID>>/"}
2020-04-27 23:29:48 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/light/shellyrgbw2-<<DEVICE-ID>>-white-0/config {"schema":"template","name":"Shelly RGBW2 <<DEVICE-ID>> Light 0","cmd_t":"~white/0/set","stat_t":"~white/0/status","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","cmd_on_tpl":"{\"turn\":\"on\"{% if brightness is defined %},\"brightness\":{{brightness|float|multiply(0.3922)|round}}{% endif %}{% if white_value is defined %},\"white\":{{white_value}}{% endif %}{% if effect is defined %},\"effect\":{{effect}}{% endif %}}","cmd_off_tpl":"{\"turn\":\"off\"}","stat_tpl":"{% if value_json.ison %}on{% else %}off{% endif %}","bri_tpl":"{{value_json.brightness|float|multiply(2.55)|round}}","uniq_id":"shellyrgbw2-<<DEVICE-ID>>-light-white-0","qos":"0","dev": {"ids": ["ECFABC<<DEVICE-ID>>"],"name":"Shelly RGBW2 <<DEVICE-ID>>","mdl":"Shelly RGBW2","sw":"20200309-104453/v1.6.0@43056d58","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-<<DEVICE-ID>>/"}
2020-04-27 23:29:48 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/binary_sensor/shellyrgbw2-<<DEVICE-ID>>-white-overpower-0/config
2020-04-27 23:29:48 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/binary_sensor/shellyrgbw2-<<DEVICE-ID>>-input-0/config
2020-04-27 23:29:48 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/binary_sensor/shellyrgbw2-<<DEVICE-ID>>-white-input-0/config
2020-04-27 23:29:49 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/sensor/shellyrgbw2-<<DEVICE-ID>>-white-power-0/config
2020-04-27 23:29:49 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/light/shellyrgbw2-<<DEVICE-ID>>-white-1/config {"schema":"template","name":"Shelly RGBW2 <<DEVICE-ID>> Light 1","cmd_t":"~white/1/set","stat_t":"~white/1/status","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","cmd_on_tpl":"{\"turn\":\"on\"{% if brightness is defined %},\"brightness\":{{brightness|float|multiply(0.3922)|round}}{% endif %}{% if white_value is defined %},\"white\":{{white_value}}{% endif %}{% if effect is defined %},\"effect\":{{effect}}{% endif %}}","cmd_off_tpl":"{\"turn\":\"off\"}","stat_tpl":"{% if value_json.ison %}on{% else %}off{% endif %}","bri_tpl":"{{value_json.brightness|float|multiply(2.55)|round}}","uniq_id":"shellyrgbw2-<<DEVICE-ID>>-light-white-1","qos":"0","dev": {"ids": ["ECFABC<<DEVICE-ID>>"],"name":"Shelly RGBW2 <<DEVICE-ID>>","mdl":"Shelly RGBW2","sw":"20200309-104453/v1.6.0@43056d58","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-<<DEVICE-ID>>/"}
2020-04-27 23:29:49 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/binary_sensor/shellyrgbw2-<<DEVICE-ID>>-white-overpower-1/config
2020-04-27 23:29:49 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/sensor/shellyrgbw2-<<DEVICE-ID>>-white-power-1/config
2020-04-27 23:29:49 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/light/shellyrgbw2-<<DEVICE-ID>>-white-2/config {"schema":"template","name":"Shelly RGBW2 <<DEVICE-ID>> Light 2","cmd_t":"~white/2/set","stat_t":"~white/2/status","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","cmd_on_tpl":"{\"turn\":\"on\"{% if brightness is defined %},\"brightness\":{{brightness|float|multiply(0.3922)|round}}{% endif %}{% if white_value is defined %},\"white\":{{white_value}}{% endif %}{% if effect is defined %},\"effect\":{{effect}}{% endif %}}","cmd_off_tpl":"{\"turn\":\"off\"}","stat_tpl":"{% if value_json.ison %}on{% else %}off{% endif %}","bri_tpl":"{{value_json.brightness|float|multiply(2.55)|round}}","uniq_id":"shellyrgbw2-<<DEVICE-ID>>-light-white-2","qos":"0","dev": {"ids": ["ECFABC<<DEVICE-ID>>"],"name":"Shelly RGBW2 <<DEVICE-ID>>","mdl":"Shelly RGBW2","sw":"20200309-104453/v1.6.0@43056d58","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-<<DEVICE-ID>>/"}
2020-04-27 23:29:49 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/binary_sensor/shellyrgbw2-<<DEVICE-ID>>-white-overpower-2/config
2020-04-27 23:29:49 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/sensor/shellyrgbw2-<<DEVICE-ID>>-white-power-2/config
2020-04-27 23:29:49 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/light/shellyrgbw2-<<DEVICE-ID>>-white-3/config {"schema":"template","name":"Shelly RGBW2 <<DEVICE-ID>> Light 3","cmd_t":"~white/3/set","stat_t":"~white/3/status","avty_t":"~online","pl_avail":"true","pl_not_avail":"false","cmd_on_tpl":"{\"turn\":\"on\"{% if brightness is defined %},\"brightness\":{{brightness|float|multiply(0.3922)|round}}{% endif %}{% if white_value is defined %},\"white\":{{white_value}}{% endif %}{% if effect is defined %},\"effect\":{{effect}}{% endif %}}","cmd_off_tpl":"{\"turn\":\"off\"}","stat_tpl":"{% if value_json.ison %}on{% else %}off{% endif %}","bri_tpl":"{{value_json.brightness|float|multiply(2.55)|round}}","uniq_id":"shellyrgbw2-<<DEVICE-ID>>-light-white-3","qos":"0","dev": {"ids": ["ECFABC<<DEVICE-ID>>"],"name":"Shelly RGBW2 <<DEVICE-ID>>","mdl":"Shelly RGBW2","sw":"20200309-104453/v1.6.0@43056d58","mf":"Allterco Robotics"},"~":"shellies/shellyrgbw2-<<DEVICE-ID>>/"}
2020-04-27 23:29:49 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/binary_sensor/shellyrgbw2-<<DEVICE-ID>>-white-overpower-3/config
2020-04-27 23:29:49 DEBUG (SyncWorker_5) [homeassistant.components.python_script.shellies_discovery.py] Send to MQTT broker: homeassistant/sensor/shellyrgbw2-<<DEVICE-ID>>-white-power-3/config

Funny thing is that in previous run I was getting empty configs for lights also - am I missing something?

Also I can see that in your case color input was set to null…

could you explain the differences +/- between this script and ShellyForHass (Shelly integration)V0.1.8 as per today, I am bit at loss which one to use to have my shelly discovered.

Not having facebook by choice, is it a good up to date youtube explainer ? on the simplest way to have a shelly device auto discovered (no yaml) into home assistant and how to have cards for them (not all light switches).

ideally a card for roller shutter (shelly 2.5), light (Shelly 1& dimmer), power meter (shelly EM).

do I need to switch on MQTT on the Shelly or keep on with rest api? too many options to choose from and so much to read to be able to make it work by tests and trials and finally make an informed decision. not Bienu fault (thank you for your work), but Shelly would gain to be more clear with an introduction of their products and protocoles used for Home Assistant environment and a simple video step by step, newbee could follow again and again.

Integration via script uses MQTT which makes it faster, more stable and more privacy-friendly in my opinion.

Thank Bienu for your reply, maybe i was just blocked by the idea to lose the option of the Shelly android app in case something went wrong with HA, which is the advantage of the rest API on MQTT.

but I also discovered, trying to communicate via chrome webpage to shelly 2.5 builtin webserver saturated/jam the wifi network. closing the page on the computer was the way to return to normal.

Now I will try with MQTT as it already work for me with Sonof/Tasmota (no yaml)

Do I need to remove shelly for Hass, to use your script ?

No but with two integrations your devices will be double in HA.

Unfortunately this script is not working for me right now.
I am abled to ‘listen’ to shelly via the MQTT tab within Developer Tools.
I suspect the first line of your debugging to be the problem:
correct MQTT configuration in Home Assistant with discovery enabled

In my configuration.yaml nothing is mentioned about MQTT, how could i solve this, so that this plugin will work in the end?

Settings -> Integration? I don’t know your config.

@Bieniu

Only this is visible/available. Is this what is meant by the ‘discovery’ option?

No. Does this integration comes from MQTT add-on? If so, discovery is enabled.

@Bieniu, yes it is.
But still it’s not working…

To continue debugging:
In the Python script, prefix is ‘homeassistant’ as it is default. The debugging instructions tell to check if it is the same as in the home assistant configuration. Where can I find this configuration? Nothing about a prefix is mentioned in my configuring.yaml

Thanks in advance!

Sorry but I don’t know your config.

New version: 0.19.0

Changelog:

  • last step of refactoring, hooray
  • BREAKING CHANGE: completely new way of configuration (per device), please read the documentation
  • add off_delay for longpush binary sensor as an option
  • BREAKING CHANGE: fix issue with entities’ unique_id

Due to the unique_id change, this version requires a special migration method. Sorry about that. It was necessary.

Migration steps:

  • remove all Shelly devices from MQTT integration ( Configuration -> Integration -> MQTT -> device -> Delete )
    image
  • update the script configuration
  • update the script via HACS or manually
  • run announce automation twice

So I have to rename all of my 400 entities again ?

Unfortunately yes.

It was easy but the hardest part was really the renaming. I finished only the main entities.
Is there any way to override the entity_id and friendly_name from the script? Or in the future plans? :wink:

Shelly H&T not adding battery. I have installed using HACS, and run through options and made sure to select battery as a sensor option. However I only get the Temp and Humidity sensors in the device. Am I missing something on the battery?

Thanks,