Have been trying for a long time to catch the mistake in my rule (you can see through the commented code).
The idea is simple. As the light gets turned on in a bathroom - play music via the local VLC . As it gets to off state. Stop playing. The problem when the light goes off via the push buttoon - everythign works nicely. When it gets shutoff cia the auto-off (motion sensor) it stops… For a second. And than starts playing again… Any ideas are much appreciated
#PLAY RADIO - CODE FOR ON
- alias: Vannaya play music
trigger:
platform: state
entity_id: light.fibaro_system_fgd212_dimmer_2_level_2_0
to: "on"
condition:
- condition: state
entity_id: input_boolean.rule_execution
state: 'on'
- condition: time
after: '9:30:00'
before: '21:30:00'
- condition: or
conditions:
- condition: state
entity_id: media_player.vannaya
state: "paused"
- condition: state
entity_id: media_player.vannaya
state: "idle"
action:
- service: media_player.volume_set
data:
entity_id: media_player.vannaya
volume_level: 0.30
- service: media_player.play_media
entity_id: media_player.vannaya
data_template:
media_content_id: >
{% if is_state("input_select.radio_station", "RelaxFM") %}
http://ic2.101.ru:8000/v13_1?setst=094548200140236612420140625&tok=75urgZKbvvpyTQMDZ1H4Hfqy5FKeKsXaPod7argnUF%2BwRqI%2Fy3MhBg%3D%3D
{%-elif is_state("input_select.radio_station", "RecordFM") %}
http://air2.radiorecord.ru:805/chil_320
{%-elif is_state("input_select.radio_station", "Classical") %}
http://174.36.206.197:8000/stream
{%-elif is_state("input_select.radio_station", "Lounge") %}
http://77.235.42.90:80/
{%-elif is_state("input_select.radio_station", "SmoothLounge") %}
http://sl128.hnux.com/
{% else %}
http://77.235.42.90:80/
{% endif %}
media_content_type: 'music'
- service: media_player.volume_set
data:
entity_id: media_player.vannaya
volume_level: 0.50
Turn the radio off
########## Turn it off
- alias: Vannaya stop music
trigger:
platform: state
entity_id: light.fibaro_system_fgd212_dimmer_2_level_2_0
to: "off"
condition:
- condition: state
entity_id: media_player.vannaya
state: "playing"
action:
# - service_template: >
# {% if states.media_player.vannaya.state == "paused" or states.media_player.vannaya.state == "idle" %}
# {% else %}
# media_player.media_play_pause
# {% endif %}
- service: media_player.media_play_pause
entity_id: media_player.vannaya
# service: media_player.media_pause
# entity_id: media_player.vannaya
Code for the light on and auto off
- alias: Bath light auto on
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_158d00010cf550
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: input_boolean.weare_away
state: 'off'
- condition: state
entity_id: light.fibaro_system_fgd212_dimmer_2_level_2_0
state: 'off'
action:
service: light.turn_on
entity_id: light.fibaro_system_fgd212_dimmer_2_level_2_0
data_template:
brightness: >
{%- if is_state("sensor.day_night", "Evening") %}
255
{%- elif is_state("sensor.day_night", "Night") %}
60
{%- else %}
255
{% endif %}
- alias: Bath light auto off
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_158d00010cf550
from: 'on'
to: 'off'
for:
minutes: 2
condition:
condition: state
entity_id: input_boolean.bathroom_occupancy
state: 'off'
action:
service: light.turn_off
entity_id: light.fibaro_system_fgd212_dimmer_2_level_2_0