helgeerbe / picframe

Picture frame viewer for raspi, controlled via mqtt and automatticly integrated as mqtt device in homeassistant.
MIT License
113 stars 32 forks source link

Feature Requests: Shutdown pi over mqtt/home assistant #312

Closed 1975felix closed 1 year ago

1975felix commented 1 year ago

it's nice to be able to turn off the display from the home assistant, but it would be nice to be able to shutdown pictureframe from the home assistant to turn it off

helgeerbe commented 1 year ago

Well, to power a pi on and off is not part of picframe. But quite easy to achieve. I use a shelly 1 (https://www.shelly.cloud/en/products/shop/shelly-plus-1) to turn power on and off.

I run 2 automations on home assistant.

Frame turn off is triggerd on calender event, no one at home, switch in home assistant.

  1. run a shell command to stop the pi
  2. wait 10 sec
  3. turn off pi

The shell command

shutdown_picframe: ssh pi@picframe 'sudo halt'

turn off

alias: FrameTurnOff
description: Bilderrahmen über den homeassistant google calendar ausschalten
trigger:
  - platform: calendar
    event: end
    offset: "0:0:0"
    entity_id: calendar.homeassistant
    id: Calendar
  - platform: state
    entity_id: group.residents
    to: not_home
    id: Bewohner
  - platform: state
    entity_id: input_boolean.picframe_power
    from: "on"
    to: "off"
    id: Power_off
condition:
  - condition: or
    conditions:
      - condition: and
        conditions:
          - condition: trigger
            id:
              - Power_off
              - Bewohner
          - condition: device
            type: is_on
            device_id: 7097dfc77369d5a50f7a1968800171bc
            entity_id: switch.picframe_power
            domain: switch
      - condition: and
        conditions:
          - condition: trigger
            id: Calendar
          - condition: template
            value_template: "{{ '#Frame' in trigger.calendar_event.summary }}"
          - condition: device
            type: is_on
            device_id: 7097dfc77369d5a50f7a1968800171bc
            entity_id: switch.picframe_power
            domain: switch
action:
  - type: turn_off
    device_id: 44e83c25884c5f5398217f9fb47e3178
    entity_id: switch.picframe_display
    domain: switch
  - service: shell_command.shutdown_picframe
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - type: turn_off
    device_id: 7097dfc77369d5a50f7a1968800171bc
    entity_id: switch.picframe_power
    domain: switch
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.picframe_power
    data: {}
mode: queued

turn on:

alias: FrameTurnOn
description: Bilderrahmen über den homeassistant google calendar einschalten
trigger:
  - platform: calendar
    event: start
    offset: "0:0:0"
    entity_id: calendar.homeassistant
    id: Calendar
  - platform: state
    entity_id: group.residents
    to: home
    id: Home
  - platform: state
    entity_id: input_boolean.picframe_power
    from: "off"
    to: "on"
    id: Power
condition:
  - condition: or
    conditions:
      - condition: and
        conditions:
          - condition: trigger
            id: Calendar
          - condition: template
            value_template: "{{ '#Frame' in trigger.calendar_event.summary }}"
      - condition: trigger
        id:
          - Home
          - Power
action:
  - type: turn_on
    device_id: 7097dfc77369d5a50f7a1968800171bc
    entity_id: switch.picframe_power
    domain: switch
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.picframe_power
    data: {}
mode: queued