From f0799d292445d34e69c7f84752da9b1778208d84 Mon Sep 17 00:00:00 2001 From: Giorgio Ravera Date: Mon, 16 Dec 2019 12:00:30 +0100 Subject: [PATCH] Added Shelly Sensors, added Shelly Reboot script, minor additional changes --- automation/shelly.yaml | 19 ++ customizations/shelly.yaml | 2 + group/shelly.yaml | 21 +++ history.yaml | 14 ++ light/sala.yaml | 68 +++---- logbook.yaml | 14 ++ recorder.yaml | 14 ++ script/shelly.yaml | 9 + sensor/shelly.yaml | 335 +++++++++++++++++++++++++++++++++ shell_command/shelly.yaml | 1 + shell_scripts/shelly_reboot.sh | 32 ++++ ui-lovelace.yaml | 20 +- 12 files changed, 502 insertions(+), 47 deletions(-) create mode 100644 automation/shelly.yaml create mode 100644 group/shelly.yaml create mode 100644 sensor/shelly.yaml create mode 100755 shell_scripts/shelly_reboot.sh diff --git a/automation/shelly.yaml b/automation/shelly.yaml new file mode 100644 index 00000000..2db456c3 --- /dev/null +++ b/automation/shelly.yaml @@ -0,0 +1,19 @@ +###################################################################### +# Shelly: Update Available Notifications +###################################################################### + +- alias: "Shelly: Notifica aggiornamento" + initial_state: 'on' + + trigger: + - platform: state + entity_id: group.shelly + to: 'on' + + action: + service: script.notify_text + data_template: + title: "Shelly - Aggiornamento" + message: "Sono disponibili aggiornamenti per i dispositivi Shelly" + enable_persistant: true + diff --git a/customizations/shelly.yaml b/customizations/shelly.yaml index 17603c23..d4f3adf1 100644 --- a/customizations/shelly.yaml +++ b/customizations/shelly.yaml @@ -4,3 +4,5 @@ script.shelly_upgrade: icon: mdi:cellphone-arrow-down +script.shelly_reboot: + icon: mdi:restart diff --git a/group/shelly.yaml b/group/shelly.yaml new file mode 100644 index 00000000..dcb49953 --- /dev/null +++ b/group/shelly.yaml @@ -0,0 +1,21 @@ +###################################################################### +# Group Shelly Devices +###################################################################### + +shelly: + name: Shelly Devices + view: true + #icon: mdi:thermometer + entities: + - sensor.shelly1_status + - sensor.shelly2_status + - sensor.shelly3_status + - sensor.shelly4_status + - sensor.shelly5_status + - sensor.shelly6_status + - sensor.shelly7_status + - sensor.shelly8_status + - sensor.shelly9_status + - sensor.shellybulb_status + - sensor.shellyem_status + - sensor.shellyplugs_status diff --git a/history.yaml b/history.yaml index d6ce8cd7..57ead76d 100644 --- a/history.yaml +++ b/history.yaml @@ -23,6 +23,7 @@ exclude: - binary_sensor.ff590mr_park_brake_status - binary_sensor.ff590mr_tire_warning - binary_sensor.ff590mr_trunk + - binary_sensor.ff590mr_fuel_lid #- binary_sensor.ff590mr_warning_brakefluid #- binary_sensor.ff590mr_warning_coolantlevellow #- binary_sensor.ff590mr_warning_washwater @@ -49,6 +50,19 @@ exclude: - sensor.ff590mr_tire_pressure_rear_left - sensor.ff590mr_tire_pressure_rear_right - sensor.ff590mr_trunk + # Shelly + - sensor.shelly1_status + - sensor.shelly2_status + - sensor.shelly3_status + - sensor.shelly4_status + - sensor.shelly5_status + - sensor.shelly6_status + - sensor.shelly7_status + - sensor.shelly8_status + - sensor.shelly9_status + - sensor.shellybulb_status + - sensor.shellyem_status + - sensor.shellyplugs_status # Energy Sensors - sensor.potenza_reattiva - sensor.tensione diff --git a/light/sala.yaml b/light/sala.yaml index 436ec19f..f22477dc 100644 --- a/light/sala.yaml +++ b/light/sala.yaml @@ -90,40 +90,40 @@ # Living Room Light (White) ###################################################################### -- platform: mqtt - name: Luce Divano Bianca - schema: template - command_topic: "shellies/shellybulb-BC8610/color/0/set" - state_topic: "shellies/shellybulb-BC8610/color/0/status" - command_on_template: > - { - "turn": "on", - "mode": "white", - {%- if color_temp is defined -%} - "temp": {{ (1000000/(((float(color_temp)-153)/354*180)+153)-35) | int }}, - {%- endif -%} - {%- if brightness is defined -%} - "brightness": {{ (brightness/255*100) | int }}, - {%- endif -%} - "effect": 0 - } - command_off_template: > - { - "turn": "off", - "mode": "white", - "effect": 0 - } - state_template: > - {% if value_json.ison == true and value_json.mode == "white" %} - on - {% else %} - off - {% endif %} - brightness_template: '{{ (value_json.brightness/100*255)|int }}' - color_temp_template: "{{ (1000000/(((float(value_json.temp)-3000)/3500*4500)+2000)) | int }}" - retain: false - qos: 0 - optimistic: false +#- platform: mqtt +# name: Luce Divano Bianca +# schema: template +# command_topic: "shellies/shellybulb-BC8610/color/0/set" +# state_topic: "shellies/shellybulb-BC8610/color/0/status" +# command_on_template: > +# { +# "turn": "on", +# "mode": "white", +# {%- if color_temp is defined -%} +# "temp": {{ (1000000/(((float(color_temp)-153)/354*180)+153)-35) | int }}, +# {%- endif -%} +# {%- if brightness is defined -%} +# "brightness": {{ (brightness/255*100) | int }}, +# {%- endif -%} +# "effect": 0 +# } +# command_off_template: > +# { +# "turn": "off", +# "mode": "white", +# "effect": 0 +# } +# state_template: > +# {% if value_json.ison == true and value_json.mode == "white" %} +# on +# {% else %} +# off +# {% endif %} +# brightness_template: '{{ (value_json.brightness/100*255)|int }}' +# color_temp_template: "{{ (1000000/(((float(value_json.temp)-3000)/3500*4500)+2000)) | int }}" +# retain: false +# qos: 0 +# optimistic: false ###################################################################### # Living Room Global diff --git a/logbook.yaml b/logbook.yaml index b0d151f9..1ba78d58 100644 --- a/logbook.yaml +++ b/logbook.yaml @@ -23,6 +23,7 @@ exclude: - binary_sensor.ff590mr_park_brake_status - binary_sensor.ff590mr_tire_warning - binary_sensor.ff590mr_trunk + - binary_sensor.ff590mr_fuel_lid #- binary_sensor.ff590mr_warning_brakefluid #- binary_sensor.ff590mr_warning_coolantlevellow #- binary_sensor.ff590mr_warning_washwater @@ -49,6 +50,19 @@ exclude: - sensor.ff590mr_tire_pressure_rear_left - sensor.ff590mr_tire_pressure_rear_right - sensor.ff590mr_trunk + # Shelly + - sensor.shelly1_status + - sensor.shelly2_status + - sensor.shelly3_status + - sensor.shelly4_status + - sensor.shelly5_status + - sensor.shelly6_status + - sensor.shelly7_status + - sensor.shelly8_status + - sensor.shelly9_status + - sensor.shellybulb_status + - sensor.shellyem_status + - sensor.shellyplugs_status # Energy Sensors - sensor.potenza_reattiva - sensor.tensione diff --git a/recorder.yaml b/recorder.yaml index 06a13923..ec1490e2 100644 --- a/recorder.yaml +++ b/recorder.yaml @@ -25,6 +25,7 @@ exclude: - binary_sensor.ff590mr_park_brake_status - binary_sensor.ff590mr_tire_warning - binary_sensor.ff590mr_trunk + - binary_sensor.ff590mr_fuel_lid #- binary_sensor.ff590mr_warning_brakefluid #- binary_sensor.ff590mr_warning_coolantlevellow #- binary_sensor.ff590mr_warning_washwater @@ -51,6 +52,19 @@ exclude: - sensor.ff590mr_tire_pressure_rear_left - sensor.ff590mr_tire_pressure_rear_right - sensor.ff590mr_trunk + # Shelly + - sensor.shelly1_status + - sensor.shelly2_status + - sensor.shelly3_status + - sensor.shelly4_status + - sensor.shelly5_status + - sensor.shelly6_status + - sensor.shelly7_status + - sensor.shelly8_status + - sensor.shelly9_status + - sensor.shellybulb_status + - sensor.shellyem_status + - sensor.shellyplugs_status # Energy Sensors - sensor.potenza_reattiva - sensor.tensione diff --git a/script/shelly.yaml b/script/shelly.yaml index ec5aa035..1518dfde 100644 --- a/script/shelly.yaml +++ b/script/shelly.yaml @@ -77,3 +77,12 @@ shelly_upgrade: data: topic: 'shellies/shellyplug-s-7A31CB/command' payload: 'update_fw' + +###################################################################### +# Shelly: Reboot +# - shell_command.shelly_reboot +###################################################################### +shelly_reboot: + alias: "Shelly: Riavvia Dispositivi" + sequence: + - service: shell_command.shelly_reboot diff --git a/sensor/shelly.yaml b/sensor/shelly.yaml new file mode 100644 index 00000000..17947ec3 --- /dev/null +++ b/sensor/shelly.yaml @@ -0,0 +1,335 @@ +###################################################################### +# Sensor: Shelly 1 +###################################################################### + +- platform: rest + scan_interval: 43200 + resource: http://shelly1.giorgioravera.it/status + method: GET + name: shelly1_status + #value_template: '{{ value_json.has_update }}' + value_template: >- + {% if value_json.has_update == True %} + on + {% else %} + off + {% endif %} + authentication: basic + username: !secret shelly_user + password: !secret shelly_password + json_attributes: + # - wifi_sta + # - mqtt + # - time + # - has_update + - mac + - update + - uptime + +###################################################################### +# Sensor: Shelly 2 +###################################################################### + +- platform: rest + scan_interval: 43200 + resource: http://shelly2.giorgioravera.it/status + method: GET + name: shelly2_status + #value_template: '{{ value_json.has_update }}' + value_template: >- + {% if value_json.has_update == True %} + on + {% else %} + off + {% endif %} + authentication: basic + username: !secret shelly_user + password: !secret shelly_password + json_attributes: + # - wifi_sta + # - mqtt + # - time + # - has_update + - mac + - update + - uptime + +###################################################################### +# Sensor: Shelly 3 +###################################################################### + +- platform: rest + scan_interval: 43200 + resource: http://shelly3.giorgioravera.it/status + method: GET + name: shelly3_status + #value_template: '{{ value_json.has_update }}' + value_template: >- + {% if value_json.has_update == True %} + on + {% else %} + off + {% endif %} + authentication: basic + username: !secret shelly_user + password: !secret shelly_password + json_attributes: + # - wifi_sta + # - mqtt + # - time + # - has_update + - mac + - update + - uptime + +###################################################################### +# Sensor: Shelly 4 +###################################################################### + +- platform: rest + scan_interval: 43200 + resource: http://shelly4.giorgioravera.it/status + method: GET + name: shelly4_status + #value_template: '{{ value_json.has_update }}' + value_template: >- + {% if value_json.has_update == True %} + on + {% else %} + off + {% endif %} + authentication: basic + username: !secret shelly_user + password: !secret shelly_password + json_attributes: + # - wifi_sta + # - mqtt + # - time + # - has_update + - mac + - update + - uptime + +###################################################################### +# Sensor: Shelly 5 +###################################################################### + +- platform: rest + scan_interval: 43200 + resource: http://shelly5.giorgioravera.it/status + method: GET + name: shelly5_status + #value_template: '{{ value_json.has_update }}' + value_template: >- + {% if value_json.has_update == True %} + on + {% else %} + off + {% endif %} + authentication: basic + username: !secret shelly_user + password: !secret shelly_password + json_attributes: + # - wifi_sta + # - mqtt + # - time + # - has_update + - mac + - update + - uptime + +###################################################################### +# Sensor: Shelly 6 +###################################################################### + +- platform: rest + scan_interval: 43200 + resource: http://shelly6.giorgioravera.it/status + method: GET + name: shelly6_status + #value_template: '{{ value_json.has_update }}' + value_template: >- + {% if value_json.has_update == True %} + on + {% else %} + off + {% endif %} + authentication: basic + username: !secret shelly_user + password: !secret shelly_password + json_attributes: + # - wifi_sta + # - mqtt + # - time + # - has_update + - mac + - update + - uptime + +###################################################################### +# Sensor: Shelly 7 +###################################################################### + +- platform: rest + scan_interval: 43200 + resource: http://shelly7.giorgioravera.it/status + method: GET + name: shelly7_status + #value_template: '{{ value_json.has_update }}' + value_template: >- + {% if value_json.has_update == True %} + on + {% else %} + off + {% endif %} + authentication: basic + username: !secret shelly_user + password: !secret shelly_password + json_attributes: + # - wifi_sta + # - mqtt + # - time + # - has_update + - mac + - update + - uptime + +###################################################################### +# Sensor: Shelly 8 +###################################################################### + +- platform: rest + scan_interval: 43200 + resource: http://shelly8.giorgioravera.it/status + method: GET + name: shelly8_status + #value_template: '{{ value_json.has_update }}' + value_template: >- + {% if value_json.has_update == True %} + on + {% else %} + off + {% endif %} + authentication: basic + username: !secret shelly_user + password: !secret shelly_password + json_attributes: + # - wifi_sta + # - mqtt + # - time + # - has_update + - mac + - update + - uptime + +###################################################################### +# Sensor: Shelly 9 +###################################################################### + +- platform: rest + scan_interval: 43200 + resource: http://shelly9.giorgioravera.it/status + method: GET + name: shelly9_status + #value_template: '{{ value_json.has_update }}' + value_template: >- + {% if value_json.has_update == True %} + on + {% else %} + off + {% endif %} + authentication: basic + username: !secret shelly_user + password: !secret shelly_password + json_attributes: + # - wifi_sta + # - mqtt + # - time + # - has_update + - mac + - update + - uptime + +###################################################################### +# Sensor: Shelly Bulb +###################################################################### + +#- platform: rest +# scan_interval: 43200 +# resource: http://shellybulb.giorgioravera.it/status +# method: GET +# name: shellybulb_status +# #value_template: '{{ value_json.has_update }}' +# value_template: >- +# {% if value_json.has_update == True %} +# on +# {% else %} +# off +# {% endif %} +# authentication: basic +# username: !secret shelly_user +# password: !secret shelly_password +# json_attributes: +# # - wifi_sta +# # - mqtt +# # - time +# # - has_update +# - mac +# - update +# - uptime + +###################################################################### +# Sensor: Shelly EM +###################################################################### + +- platform: rest + scan_interval: 43200 + resource: http://shellyem.giorgioravera.it/status + method: GET + name: shellyem_status + #value_template: '{{ value_json.has_update }}' + value_template: >- + {% if value_json.has_update == True %} + on + {% else %} + off + {% endif %} + authentication: basic + username: !secret shelly_user + password: !secret shelly_password + json_attributes: + # - wifi_sta + # - mqtt + # - time + # - has_update + - mac + - update + - uptime + +###################################################################### +# Sensor: Shelly Plug S +###################################################################### + +#- platform: rest +# scan_interval: 43200 +# resource: http://shellyplugs.giorgioravera.it/status +# method: GET +# name: shellyplugs_status +# #value_template: '{{ value_json.has_update }}' +# value_template: >- +# {% if value_json.has_update == True %} +# on +# {% else %} +# off +# {% endif %} +# authentication: basic +# username: !secret shelly_user +# password: !secret shelly_password +# json_attributes: +# # - wifi_sta +# # - mqtt +# # - time +# # - has_update +# - mac +# - update +# - uptime diff --git a/shell_command/shelly.yaml b/shell_command/shelly.yaml index 56b2867a..229e12c1 100644 --- a/shell_command/shelly.yaml +++ b/shell_command/shelly.yaml @@ -1 +1,2 @@ shelly_upgrade: 'bash /var/lib/homeassistant/.homeassistant/shell_scripts/shelly_upgrade.sh' +shelly_reboot: 'bash /var/lib/homeassistant/.homeassistant/shell_scripts/shelly_reboot.sh' diff --git a/shell_scripts/shelly_reboot.sh b/shell_scripts/shelly_reboot.sh new file mode 100755 index 00000000..2be5768c --- /dev/null +++ b/shell_scripts/shelly_reboot.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +HASS_HOME="/var/lib/homeassistant/.homeassistant" +USER=$(awk '/shelly_user/ { print $2 }' $HASS_HOME/secrets.yaml) +PASSWORD=$(awk '/shelly_password/ { print $2 }' $HASS_HOME/secrets.yaml) +SHELLY_ID=( + shelly1.giorgioravera.it + shelly2.giorgioravera.it + shelly3.giorgioravera.it + shelly4.giorgioravera.it + shelly5.giorgioravera.it + shelly6.giorgioravera.it + shelly7.giorgioravera.it + shelly8.giorgioravera.it + shelly9.giorgioravera.it + shellybulb.giorgioravera.it + shellyem.giorgioravera.it + shellyplugs.giorgioravera.it +) + +echo "Reboot Shelly Devices" + +for i in "${SHELLY_ID[@]}" +do + ALIVE=$(ping -c 1 $i |grep ttl) + if [ ! -z "$ALIVE" ]; then + STATUS=$(curl -s --user $USER:$PASSWORD http://$i/reboot | sed -e "s/{"ok"}://g") + echo $STATUS + fi +done + +echo "Done" diff --git a/ui-lovelace.yaml b/ui-lovelace.yaml index 027001ed..d47c30eb 100644 --- a/ui-lovelace.yaml +++ b/ui-lovelace.yaml @@ -51,7 +51,7 @@ views: #entity: group.lights_livingroom entities: - light.luce_divano - - light.luce_divano_bianca + #- light.luce_divano_bianca - cover.tapparella_sala - climate.sala_termostato_sala - media_player.tv_sala @@ -157,7 +157,7 @@ views: - light.luce_corridoio - light.luci_sala - light.luce_divano - - light.luce_divano_bianca + #- light.luce_divano_bianca - light.luci_bagno - light.luce_bagno - light.luce_specchio @@ -184,9 +184,9 @@ views: name: Luce Divano entity: light.luce_divano - - type: light - name: Luce Divano Bianca - entity: light.luce_divano_bianca +# - type: light +# name: Luce Divano Bianca +# entity: light.luce_divano_bianca - type: light name: Luci Bagno @@ -1425,19 +1425,13 @@ views: # entity_id: script.homeassistant_upgrade - type: horizontal-stack - cards: + cards: - type: entities title: Operazione sui Dispositivi show_header_toggle: false entities: - script.shelly_upgrade -# - type: entity-button -# entity: script.shelly_upgrade -# tap_action: -# action: call-service -# service: script.turn_on -# service_data: -# entity_id: script.shelly_upgrade + - script.shelly_reboot - type: vertical-stack cards: -- 2.47.3