Skip to content

Commit

Permalink
Turn on or off Magic Mirror screen from motion sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarb committed Dec 2, 2019
1 parent 412930b commit c37eb27
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .HA_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.98.1
0.100.1
27 changes: 21 additions & 6 deletions automations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,29 @@
from: 'off'
platform: state
to: 'on'
- entity_id: switch.hallway_sideboard_light
from: 'off'
platform: state
to: 'on'
condition: []
action:
- service: script.turn_magic_mirror_screen_on
- id: '1564525145783'
alias: Hallway motion absence turns off tablet
trigger:
- entity_id: switch.hallway_motion_sensor
from: 'on'
platform: state
to: 'off'
- entity_id: switch.hallway_sideboard_light
from: 'on'
platform: state
to: 'off'
condition: []
action:
- service: rest_command.wake_up_device
data:
device_ip: !secret magic_mirror_ip
device_port: 1817
- service: script.turn_magic_mirror_screen_off
- id: '1569245264705'
alias: Bathroom motions turns on bathroom ceiling lamp
alias: Bathroom motion turns on bathroom ceiling lamp
trigger:
- entity_id: switch.bathroom_motion_sensor
from: 'off'
Expand All @@ -34,4 +49,4 @@
action:
- data:
entity_id: light.bathroom_ceiling
service: light.turn_off
service: light.turn_off
36 changes: 35 additions & 1 deletion configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,26 @@ map:
# Track the sun
sun:

# MQTT
mqtt:
broker: !secret mqtt_broker_ip
discovery: true
discovery_prefix: homeassistant

# Global variables for templates
input_text:
video_url:
name: Video URL
initial: !secret magic_mirror_video

# Binary sensors

binary_sensor:
- platform: rest
resource: !secret magic_mirror_device_info
name: Magic Mirror Screen
value_template: '{{ value_json.isScreenOn }}'

# Switches
switch:
- platform: wake_on_lan
Expand All @@ -68,8 +82,22 @@ switch:
turn_off:
service: script.turn_computer_off

- platform: rest
resource: !secret magic_mirror_fully_api
name: Magic Mirror REST
body_on: '{"cmd": "screenOn"}'
body_off: '{"cmd": "screenOff"}'
is_on_template: "{{ is_state('binary_sensor.magic_mirror_screen', 'on') }}"

- platform: template
switches:
magic_mirror:
friendly_name: Magic Mirror
value_template: "{{ is_state('binary_sensor.magic_mirror_screen', 'on') }}"
turn_on:
service: script.turn_magic_mirror_screen_on
turn_off:
service: script.turn_magic_mirror_screen_off
hallway_camera:
friendly_name: Show hallway camera on TV
value_template: "{{ is_state_attr('media_player.chromecast_ultra', 'media_content_id', states('input_text.video_url')) }}"
Expand Down Expand Up @@ -188,8 +216,14 @@ hacs:

# HTTP Requests
rest_command:
wake_up_device:
turn_on_screen_autoremote:
url: http://{{ device_ip }}:{{ device_port }}/?message=on
turn_on_screen_fully:
url: http://{{ device_ip }}:{{ device_port }}/?cmd=screenOn&type=json&password={{ password }}
turn_off_screen_autoremote:
url: http://{{ device_ip }}:{{ device_port }}/?message=of
turn_off_screen_fully:
url: http://{{ device_ip }}:{{ device_port }}/?cmd=screenOff&type=json&password={{ password }}

# Generic camera
camera:
Expand Down
15 changes: 13 additions & 2 deletions scripts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,21 @@ cast_magic_mirror_camera:
turn_magic_mirror_screen_on:
alias: Turn on Magic Mirror screen
sequence:
- service: rest_command.wake_up_device
- service: rest_command.turn_on_screen_fully
data:
device_ip: !secret magic_mirror_ip
device_port: !secret magic_mirror_wake_up_port
device_port: !secret magic_mirror_fully_port
password: !secret magic_mirror_fully_password


turn_magic_mirror_screen_off:
alias: Turn off Magic Mirror screen
sequence:
- service: rest_command.turn_off_screen_fully
data:
device_ip: !secret magic_mirror_ip
device_port: !secret magic_mirror_fully_port
password: !secret magic_mirror_fully_password

turn_computer_on:
alias: Turn on computer
Expand Down

0 comments on commit c37eb27

Please sign in to comment.