Created
December 14, 2023 22:42
-
-
Save timurvafin/11432302780f756c14f4c8579bbb04f5 to your computer and use it in GitHub Desktop.
Tion HA Automation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# blueprints/automation/timurvafin/tion.yaml | |
blueprint: | |
name: Tion Climate Control | |
description: Controls a Tion climate device based on fan speed, HVAC mode, and temperature sensors. | |
domain: automation | |
input: | |
climate_device: | |
name: Climate Device | |
selector: | |
entity: | |
domain: climate | |
fan_speed_sensor: | |
name: Fan Speed Sensor | |
selector: | |
entity: | |
domain: sensor | |
hvac_mode_sensor: | |
name: HVAC Mode Sensor | |
selector: | |
entity: | |
domain: sensor | |
temperature_sensor: | |
name: Temperature Sensor | |
selector: | |
entity: | |
domain: sensor | |
people_group: | |
name: People Group | |
selector: | |
entity: | |
domain: group | |
trigger: | |
- platform: state | |
entity_id: !input fan_speed_sensor | |
to: "0" | |
id: fan_speed_off | |
- platform: state | |
entity_id: !input fan_speed_sensor | |
to: ["1", "2", "3", "4"] | |
id: fan_speed_change | |
- platform: state | |
entity_id: !input temperature_sensor | |
id: temperature_change | |
- platform: state | |
entity_id: !input hvac_mode_sensor | |
id: hvac_mode_change | |
variables: | |
climate_device_entity: !input climate_device | |
fan_speed_sensor_entity: !input fan_speed_sensor | |
temperature_sensor_entity: !input temperature_sensor | |
hvac_mode_sensor_entity: !input hvac_mode_sensor | |
people_group_entity: !input people_group | |
action: | |
- choose: | |
- conditions: "{{ trigger.id == 'fan_speed_change' }}" | |
sequence: | |
# turn on if someone at home and it's off | |
- if: | |
- "{{ is_state(people_group_entity, 'home') }}" | |
- "{{ is_state(climate_device_entity, 'off') }}" | |
then: | |
- delay: "{{ range(1, 3) | random }}" | |
- service: climate.set_temperature | |
target: | |
entity_id: !input climate_device | |
data: | |
hvac_mode: "{{ states(hvac_mode_sensor_entity) }}" | |
temperature: "{{ states(temperature_sensor_entity) }}" | |
# update fan speed if different | |
- if: | |
- "{{ state_attr(climate_device_entity, 'fan_mode') != states(fan_speed_sensor_entity) }}" | |
then: | |
- delay: "{{ range(1, 3) | random }}" | |
- service: climate.set_fan_mode | |
entity_id: !input climate_device | |
data: | |
fan_mode: "{{ states(fan_speed_sensor_entity) }}" | |
- conditions: "{{ trigger.id == 'fan_speed_off' }}" | |
sequence: | |
- if: | |
- "{{ is_state(climate_device_entity, ['heat', 'fan_only']) }}" | |
then: | |
- delay: "{{ range(1, 3) | random }}" | |
- service: climate.turn_off | |
target: | |
entity_id: !input climate_device | |
- conditions: "{{ trigger.id in ['temperature_change', 'hvac_mode_change'] }}" | |
sequence: | |
- if: | |
- "{{ is_state(climate_device_entity, ['heat', 'fan_only']) }}" | |
then: | |
- delay: "{{ range(1, 3) | random }}" | |
- service: climate.set_temperature | |
target: | |
entity_id: !input climate_device | |
data: | |
hvac_mode: "{{ states(hvac_mode_sensor_entity) }}" | |
temperature: "{{ states(temperature_sensor_entity) }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# custom_templates/tion.jinja | |
{% macro calculate_tion_fan_speed(co2_sensor_entity, co2_limit1=None, co2_limit2=None, co2_limit3=None, co2_limit4=None, co2_limit5=None, co2_limit6=None) %} | |
{% set co2 = states(co2_sensor_entity) | int(0) %} | |
{% set fan_speeds = [ co2_limit1, co2_limit2, co2_limit3, co2_limit4, co2_limit5, co2_limit6 ] %} | |
{{ fan_speeds | reject('equalto', None) | select('lt', co2) | list | length }} | |
{% endmacro %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# packages/areas/bedroom.yaml | |
template: | |
sensor: | |
- unique_id: sensor.bedroom_tion_target_fan_speed | |
name: 'Bedroom Tion - Target fan speed' | |
icon: mdi:fan-auto | |
state: > | |
{% from "tion.jinja" import calculate_tion_fan_speed %} | |
{{ calculate_tion_fan_speed('sensor.bedroom_air_co2', 550, 650, 700, 750) | trim }} | |
automation: | |
- id: bedroom_tion_blueprint | |
alias: "Bedroom - Tion Climate Control" | |
use_blueprint: | |
path: timurvafin/tion.yaml | |
input: | |
people_group: group.people | |
climate_device: climate.tion_bedroom | |
fan_speed_sensor: sensor.bedroom_tion_target_fan_speed | |
hvac_mode_sensor: sensor.tion_target_hvac_mode | |
temperature_sensor: sensor.tion_target_temperature |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# packages/integrations/tion.yaml | |
template: | |
sensor: | |
- unique_id: sensor.tion_target_temperature | |
name: "Tion - Target temperature" | |
unit_of_measurement: "°C" | |
icon: mdi:temperature-celsius | |
state: > | |
{% set outside_temperature = states('sensor.zont_outside_temperature') | float(0) %} | |
{{ 19 if outside_temperature < 0 else 0 }} | |
- unique_id: sensor.tion_target_hvac_mode | |
name: "Tion - Target HVAC mode" | |
icon: mdi:hvac | |
state: > | |
{% set target_temperature = states('sensor.tion_target_temperature') | int(0) %} | |
{{ 'heat' if target_temperature > 0 else 'fan_only' }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment