Automations problems

Hi everyone I´m very new to all of these, and I´m working on my first automations, I have some already running but I have two of them that I´ve already tried to do a lot and it doesn´t work at all, first is a automation that turn on the tv when I arrive at home and my phone is detected by my router, but I´m trying to put a condition to not turn on when it´s already on, otherwise if I left the network for some reason it switch again and turn it off, here´s my confi.yaml:

alias: turn on tv when arrive at home
trigger:

  • entity_id: device_tracker.2c4d54de5ed3
    from: not_home
    platform: state
    to: home
    condition:
  • condition: state
    entity_id: switch.tv
    state: ‘off’
    action:
  • data:
    entity_id: switch.tv
    service: switch.turn_on
    The second is to not turn off my led in my motion detected when I arrive home:
- id: '1530727435325'
  alias: Turn off motion sensor when at home
  trigger:
  - entity_id: device_tracker.2c4d54de5ed3
    from: Not home
    platform: state
    to: Home
  condition: []
  action:
  - data:
      Entity_id: automation_d1_motion_on
    service: automation.turn_off

tks very much

- alias: "description"
  trigger:
    platform: state
    from: 'not_home'
    to: 'home'
  condition:
    condition: state
    entity_id: switch.tv
    state: 'off'
  action:
    service: switch.turn_on
    entity_id: switch.tv
- alias: "Turn off motion sensor"
  trigger:
    platform: state
    entity_id: device_tracker.2c4d54de5ed3
    from: 'not_home'
    to: 'home'
  action:
    service: automation.turn_off
    entity_id: automation.d1_motion_on

You don’t need a condition if there is no condition.

The condition should be only turn on if its off, otherwise would switch again and turn off while somebody is watching

Is your tv smart? Can you see the TV switch state in HA?

yes it is smart but couldn´t find support for homeassistant yet is a old LG and it doesn´t work with neither webos or netcast.

I´m using broadlink as a ir sender so doesn´t state if it´s on or off.

You’ll need a way to detect the TV being on if you want to add that condition. From the sounds of it, you don’t have that?

Only have switches in homeassistant, if my switch state is already on at homeassistant shouldn´t be possible to work on that automation ?

So if it connects to your wifi you can create a binary sensor like this:

- platform: command_line
  scan_interval: 5
  name: living_tv
  command: ping -W 1 -c 1 tvip > /dev/null 2>&1 && echo success || echo false
  device_class: connectivity
  payload_on: "success"
  payload_off: "false"

you can then use it as a condition in your automation.

Ohhh I didn´t know this component, very noobie to all of these, tks will try today and give you a feedback.

Quick question is the automation correct? and what about my motion automation what did I do wrong?

on the tv automation replace in the condition section the switch.tv for this sensor which in this specific example would be called binary_sensor.living_tv

the motion sensor if I understand correctly, will turn off an automation called automation.d1_motion_on
when the device changes to home

about the motion automation for some reason it´s not turning off my other atumation don´t know if the error is on the zone home and not home ?

the trigger seems ok. try homeassistant.turn_off instead of automation.turn_off

when I trigged manually it worked, but I think something is wrong with the trigger, because I´m off my netwrok and even though is still runnning

it worked, don´t know what I did but it seems that using the internal automation tools in hassio is making mistakes so I rewrote in config.yaml and worked, also was great abou the binary sensor tks very much