I Have this code in automation.yaml. And it will simply not trigger every 1 min. That I set as a time trigger, why does it not work ?? Please help!
alias: Tesla Model Y Charging Amperage Adjustment
description: 'Telsa auto set'
trigger:
- platform: time_pattern
minutes: "/1"
condition:
- condition: sun
after: sunrise
before: sunset
- condition: state
entity_id: switch.model_y_charger
state: 'on'
- condition: template
value_template: "{{ states('sensor.combined_solar_power') | float >= 720 }}"
action:
- variables:
solar_power: '{{ ((states(''sensor.solax_x3_powerdc1'') | float) + (states(''sensor.solax_x3_powerdc2'') | float)) }}'
charging_amps: >-
{% set solar_power = ((states('sensor.solax_x3_powerdc1') | float) + (states('sensor.solax_x3_powerdc2') | float)) %}
{% set max_charging_amps = 13 %}
{% set max_solar_power = max_charging_amps * ((3 ** 0.5) * 400 * 1) %}
{% if solar_power > max_solar_power %}
{{ max_charging_amps }}
{% else %}
{{ (solar_power / ((3 ** 0.5) * 400 * 1)) | int }}
{% endif %}
- service: system_log.write
data:
message: 'Solar Power: {{ solar_power }}, Charging Amps: {{ charging_amps }}'
level: info
- choose:
- conditions:
- condition: template
value_template: "{{ states('sensor.combined_solar_power') | float < 720 }}"
sequence:
- service: switch.turn_off
entity_id: switch.model_y_charger
- conditions:
- condition: template
value_template: "{{ states('sensor.combined_solar_power') | float >= 720 }}"
sequence:
- service: number.set_value
target:
entity_id: number.model_y_charging_amps
data:
value: '{{ charging_amps }}'
mode: single
Hellis81
(Hellis81)
April 7, 2023, 7:17pm
2
Why do you want to time pattern this?
I can’t see any reason.
Just use the same as you have in your conditions as the trigger.
Since it’s a time pattern trigger there must be some failed traces we can look at.
I am doing it to test out the Automation, because before I set it to be every time my solar system send a value, but I didn’t want to wait so I set it as a time.
So before the script worked if I use this:
alias: Tesla Model Y Charging Amperage Adjustment
description: ' '
trigger:
- platform: state
entity_id: sensor.combined_solar_power
condition:
- condition: time
after: 09:00:00
before: '22:00:00'
weekday:
- mon
- tue
- wed
- thu
- fri
- sat
- sun
- condition: zone
entity_id: device_tracker.model_y_location_tracker
zone: zone.home
action:
- variables:
solar_power: '{{ ((states(''sensor.solax_x3_powerdc1'') | float) + (states(''sensor.solax_x3_powerdc2'') | float)) }}'
charging_amps: >-
{% set raw_amps = solar_power / ((3 ** 0.5) * 400 * 1) %}
{{ (raw_amps | float) | round(0, 'floor') }}
- service: system_log.write
data:
message: 'Solar Power: {{ solar_power }}, Charging Amps: {{ charging_amps }}'
level: info
- service: number.set_value
target:
entity_id: number.model_y_charging_amps
data:
value: '{{ charging_amps }}'
mode: single
But as soon as i use the other script I just posted before it does not work. But the script runs when I do it manually just not automatically
How would I do that ? Will it run all the time then ?
Hellis81
(Hellis81)
April 7, 2023, 7:24pm
6
I think we have a misunderstanding here.
With time pattern you must wait for the time pattern, but if you trigger on a sensor then it will trigger as soon as the sensor updates and all conditions are meet.
Any traces?
But it does not trigger when I use the first code I posted. (Only if I trigger the automation manually) While the second code it does no matter what trigger I use, automatically
Hellis81
(Hellis81)
April 7, 2023, 7:29pm
8
JacobFChristensen:
How would I do that ?
Do what?
Automations trigger when a trigger goes from false to true.
So if we take your sensor.combined_solar_power, if that is at 500, then goes to 800 then it triggers.
But if it then keeps above 720 then it will not trigger again until it has gone below 720 and then back up above 720 again.
So it does not trigger because I have this line? (Unless my solar_power goes over 720) :
How would I “Just use the same as you have in your conditions as the trigger.” ?
Hellis81
(Hellis81)
April 7, 2023, 7:33pm
11
Correct.
You listed it as a condition so it will be a condition
Oh dang…
I am completely blind
But wouldn’t I still be able to see the automation run but stop at the condition? Becuase it does not run at all on the trigger
Hellis81
(Hellis81)
April 7, 2023, 9:49pm
14
Make this your triggers:
trigger:
- platform: sun
event: sunrise
offset: 0
- platform: state
entity_id: switch.model_y_charger
state: 'on'
- platform: template
value_template: "{{ states('sensor.combined_solar_power') | float >= 720 }}"