Automation, Script, Scene or Other?

Hello!

Beginner here, trying to do my initial setup, and I am having a hard time differentiating between using automation, script, scene or another component. Here is one setup I am trying to configure:

Every weekday morning at 6 am, only run if group.household home

  1. TV Power on - Picture Mode
    If TV is on {% if is_state(‘binary_sensor.ping_mb_vizio_tv’, ‘on’) %}
    Call service remote.send_command, send 4 commands to
    iTach IP2IR (Changes picture mode)
    If TV is not on
    Turn it on
    Run same commands above (changes picture mode)
  2. Change Channel on DirecTV to News
  3. Wait 5 minutes
  4. Set Receiver to -40 Volume
  5. Turn on Receiver Zone 2

Where I am confused is 1. Do I use Automation for above, and call scripts? If so, how do I set conditions for certain actions vs. condition for all?

Thanks for any help,
Cody

Since your going to do a sequence of things a script would be the easiest way for you to go.
I would do a combination myself.

automation:
  - alias: tv_time
    trigger:
      - platform: time
        at: 06:00:00
    action:
      service: script.turn_on
      entity_id: script.its_tv_time
    condition:
      - condition: state
        entity_id: group.household
        state: 'home'
script:
  its_tv_time:
    sequence:
      - condition: state
        entity_id: group.household
        state: 'home'
      - service: homeassistant.turn_on
        entity_id: binary_sensor.ping_mb_vizio_tv

      .....etc

Condition check for both the automation and script since it’s “cheap” and would prevent eventual triggering.

For how a script works the documentation is really good at explaining conditions and delays :slight_smile:

The action part of an automation is a script, so calling a script is pretty pointless unless you’re going to use it multiple times.

automation:
  - alias: tv_time
    trigger:
      platform: time
      at: 06:00:00
    condition:
      condition: state
      entity_id: group.household
      state: 'home'
    action:
      - service: homeassistant.turn_on
        entity_id: binary_sensor.ping_mb_vizio_tv
      - delay: 00:05:00
      - service: media_player.volume_set
      .....etc

Today I learned something new :joy:

2 Likes

Thank you for your replies, however, I am not quite sure on how to incorporate the TV on/off based on the examples. The ping sensor tells me if it is on or off, and based on that, it would send command to turn on (if it’s off) or not send anything if it’s already on. So I would need that as well as group.household = home

Is the command a toggle? (if you send the command when it is already on, does it switch off?)

Yes it’s a toggle, and the On/Off works, but it doesn’t know the TV state due to it being IR, which is why I have the ping sensor. For example, if the TV is already On, but an automation also runs to turn it on, it will turn it off instead, since it doesn’t know it’s already on.

If that makes any sense

Yeah, perfect sense.

In that case you do need to split it out in to scripts, one for if the TV is on and one for if it’s off.

automation:
  - alias: tv_time
    trigger:
      platform: time
      at: 06:00:00
    condition:
      condition: state
      entity_id: group.household
      state: 'home'
    action:
      service_template: >
        {% if is_state ('binary_sensor.ping_mb_vizio_tv' ,  'on' %} script.one
        {% else %} script.two {% endif %}

script:
  one:
    sequence:
      - STRAIGHT IN TO SETTING CHANNELS 

  two:
    sequence:
      - service: homeassistant.turn_on 
        entity_id: switch.YOUR_TV
      - service: script.one
1 Like

Awesome, I’ll try that out and see how it goes. Thank you for your assistance

1 Like