Aephir / HomeAssistant2

Second version of homeassistant, now running on Raspbian Stretch Lite (RPi3)
0 stars 0 forks source link

Make proper upgrade of mopidy and IRIS from HASS #11

Open Aephir opened 6 years ago

Aephir commented 6 years ago

I made the .sh file, made a shell_command in hass, and a script calling the shell_command.

Aephir commented 6 years ago

Just do on/off sensing:

Sensor:

- platform: template
  sensors:
    kettle:
      friendly_name: "Media in Use"
      value_template: ->
        {% if is_state('switch.fibaro_system_fgwpef_wall_plug_gen5_switch', 'off') %}
          off
#        {% elif states.sensor.fibaro_system_fgwpef_wall_plug_gen5_power.attributes.w|float < 8 %}
#          standby
        {% elif is_state('switch.fibaro_system_fgwpef_wall_plug_gen5_switch', 'on') %}
          on
        {% else %}
          failed
        {% endif %}

Automation:

Maybe I can make one long automation as this:

- alias: "upgrade mopidy"
  trigger:
    - platform: script
      entity_id: script.trigger_mopidy_upgrade
  action:
    - action: template
      value_template: ->
        {% if is_state('switch.fibaro_system_fgwpef_wall_plug_gen5_switch', 'off') %}
          service: homeassistant.turn_on
          entity_id: script.mopidy_upgrade_off
#        {% elif states.sensor.fibaro_system_fgwpef_wall_plug_gen5_power.attributes.w|float < 8 %}
#          service: homeassistant.turn_on
#          entity_id: script.mopidy_upgrade_standby
        {% elif is_state('switch.fibaro_system_fgwpef_wall_plug_gen5_switch', 'on') %}
          service: homeassistant.turn_on
          entity_id: script.mopidy_upgrade_on
        {% else %}
          failed
        {% endif %}

Or this:

- alias: "upgrade mopidy"
  trigger:
    - platform: script
      entity_id: script.trigger_mopidy_upgrade
  action:
    - service: script.turn_on
      value_template:
        entity_id: >
          {% if is_state('switch.fibaro_system_fgwpef_wall_plug_gen5_switch', 'off') %}
            service: homeassistant.turn_on
            entity_id: script.mopidy_upgrade_off
#          {% elif states.sensor.fibaro_system_fgwpef_wall_plug_gen5_power.attributes.w|float < 8 %}
#            service: homeassistant.turn_on
#            entity_id: script.mopidy_upgrade_standby
          {% elif is_state('switch.fibaro_system_fgwpef_wall_plug_gen5_switch', 'on') %}
            service: homeassistant.turn_on
            entity_id: script.mopidy_upgrade_on
          {% else %}
            failed
          {% endif %}

Otherwise split them up as such:

- alias: "upgrade mopidy"
  trigger:
    - platform: script
      entity_id: script.trigger_mopidy_upgrade
  condition:
    - condition: state
      entity_id: sensor.media_in_use
      state: 'off'
  action:
    service: homeassistant.turn_on
    entity_id: script.mopidy_upgrade_off
- alias: "upgrade mopidy"
  trigger:
    - platform: script
      entity_id: script.trigger_mopidy_upgrade
  condition:
    - condition: state
      entity_id: sensor.media_in_use
      state: 'standby'
  action:
    service: homeassistant.turn_on
    entity_id: script.mopidy_upgrade_standby
- alias: "upgrade mopidy"
  trigger:
    - platform: script
      entity_id: script.trigger_mopidy_upgrade
  condition:
    - condition: state
      entity_id: sensor.media_in_use
      state: 'on'
  action:
    service: homeassistant.turn_on
    entity_id: script.mopidy_upgrade_on

Script:

  trigger_mopidy_upgrade:
    alias: Trigger Mopidy Upgrade
    sequence:
      - service: automation.trigger
        entity_id: automation.upgrade_mopidy
  mopidy_upgrade_off:
    alias: Upgrade Mopidy
    sequence:
      - service: switch.turn_on
         data:
           entity_id: switch.fibaro_system_fgwpef_wall_plug_gen5_switch
      - delay: 00:00:30
      - service: shell_command.upgrade_mopidy
      - delay: 00:02:30
      - service: switch.turn_off
         data:
           entity_id: switch.fibaro_system_fgwpef_wall_plug_gen5_switch
  mopidy_upgrade_on:
    alias: Upgrade Mopidy
    sequence:
      - service: shell_command.upgrade_mopidy

Shell Command:

upgrade_mopidy: /home/homeassistant/.homeassistant/shell_scripts/upgrade_mopidy.sh

bash:

#!/bin/bash

ssh -p 145 -i /home/homeassistant/connection/privatekey_libreelec pi@192.168.0.145 "sudo apt-get update && sudo apt-get upgrade -y && sudo pip install --upgrade Mopidy-Iris"