Does this automation perform like I think it does?

From 8:14:59PM to 12:00:00AM, the automation will run every 30 minutes to update the entity binary_sensor.model_y_charge_cable.

This is to determine if my charge cable is connected.

If during the same time period, the automation determines the charge cable is connected it will disable the automation. It will stop polling the status of the entity binary_sensor.model_y_charge_cable

alias: Update Tesla Charge Cable Status
description: ""
triggers:
  - trigger: time_pattern
    minutes: /30
conditions:
  - condition: time
    after: "20:14:59"
    before: "00:00:00"
actions:
  - action: homeassistant.update_entity
    data:
      entity_id:
        - binary_sensor.model_y_charge_cable
  - if:
      - condition: state
        entity_id: binary_sensor.model_y_charge_cable
        state: "on"
    then:
      - action: automation.turn_off
        metadata: {}
        data:
          stop_actions: true
        target:
          entity_id: automation.update_tesla_charge_cable_status
mode: single

I want this automation only to run if my car is home. So I set up another automation where it will first poll to see if the car is home. Then if the car is home it will enable/disable the above automation.

alias: Enable Update Tesla Charge Cable Status Automation
description: ""
triggers:
  - trigger: time
    at: "20:14:57"
    id: 8:14:57 PM
  - trigger: time
    at: "20:14:58"
    id: 8:14:58 PM
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - 8:14:57 PM
        sequence:
          - action: homeassistant.update_entity
            data:
              entity_id:
                - device_tracker.model_y_location
      - conditions:
          - condition: trigger
            id:
              - 8:14:58 PM
          - condition: state
            entity_id: device_tracker.model_y_location
            state: home
        sequence:
          - action: automation.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: automation.update_tesla_charge_cable_status
      - conditions:
          - condition: trigger
            id:
              - 8:14:58 PM
          - condition: state
            entity_id: device_tracker.model_y_location
            state: not_home
        sequence:
          - action: automation.turn_off
            metadata: {}
            data:
              stop_actions: true
            target:
              entity_id: automation.update_tesla_charge_cable_status
mode: single

If the cable is connected between those hours, the charger will turn on if it is after 8:15pm M-F, anytime the cable is connected on Sat or Sun

alias: Tesla Charger On
description: ""
triggers:
  - trigger: time_pattern
    minutes: /30
conditions:
  - condition: time
    after: "20:14:59"
    before: "00:00:00"
actions:
  - if:
      - condition: state
        entity_id: binary_sensor.model_y_charge_cable
        state: "on"
    then:
      - condition: time
        weekday:
          - mon
          - tue
          - wed
          - thu
          - fri
        after: "20:15:00"
      - action: switch.turn_on
        target:
          entity_id: switch.tesla_charger
        data: {}
  - if:
      - condition: state
        entity_id: binary_sensor.model_y_charge_cable
        state: "on"
    then:
      - condition: time
        weekday:
          - sun
          - sat
      - action: switch.turn_on
        target:
          entity_id: switch.tesla_charger
        data: {}
mode: single

At first glance it looks to do what you want (but there are indeed more experienced users on here); however, I can’t help but wonder if there is a more eloquent solution to what you’re doing as you are currently running 3 automations, one being used just to turn the other on/off.

I don’t have these devices or sensors, but I’m guessing they don’t update frequently enough to run simple: if plugged in, and the time is 20:15-00:00, turn on type deal?

I won’t rewrite the entire automation in YAML, but maybe something like the following logistical flow to keep it all within 1 automation


Trigger: time is 20:15
Conditions:

  • Model Y is “home”
  • Weekday is Mon, Tue, Wed, Thu, Fri

Actions: (this part I quickly put in YAML as its just easier to follow my thoughts)

actions:
  - repeat:
      sequence:
        - action: homeassistant.update_entity
          data:
            entity_id:
              - binary_sensor.model_y_charge_cable
        - delay:
            minutes: 30
      until:
        - condition: or
          conditions:
            - condition: state
              entity_id: binary_sensor.model_y_charge_cable
              state: "on"
            - condition: time
              after: "00:00:00"
  - if:
      - condition: state
        entity_id: binary_sensor.model_y_charge_cable
        state: "on"
    then:
      - action: switch.turn_on
        target:
          entity_id: switch.tesla_charger

So, at 8:15pm everyday, only if the car is home and if the day is Mon-Friday, the action part will

  1. repeat update the charge_cable entity every 30 minutes until it evaluates to “on” OR the time is after midnight
  2. then evaluate an IF; if the cable sensor is “on” then turn the switch on. [should also have an else here, but up to you how exactly you want to handle it all]

Why don’t you just use the fact that the car is home (or not) as a condition in your first automation?

1 Like

It does not poll fast enough right now

I cannot figure out how often it polls. All I know is the integration is cloud polling.

The integration uses cloud polling. I haven’t been able to figure out how often it polls.

My rough estimate is anywhere from 1-4 hours based on how my automations have been running. I haven’t dug deep enough to figure it out.

Thank you! I’ll look at your code and rethink this.

I wasn’t sure if actions are processed in order.

Ya, don’t feel like you have to copy that YAML code. Feel free to tweak to your needs. E.x. if you get home at 9pm, this automation won’t run as you were not home at 8:15, so you would remove the Model Y being home as an automation condition, and move it down into the Repeat entity update loop and add another end condition for it.

Via the GUI it’s quite straightforward to setup. Look for the OR conditions and the Repeat actions in the “building blocks” section under actions.