Hallo iedereen,
ik wil mijn ventilatiesysteem automatiseren op basis van een aantal regels:
- als een CO2-sensor in de slaapkamers of woonkamer meer dan 1000ppm CO2 aangeeft, of
- de vochtigheid in de badkamer hoger is dan 70%, of
- de lamp op het toilet langer dan 90 seconden aanstaat (want dat wijst op een number 2)
Dan moet de rpm van de ventilator naar 60% (meer is niet noodzakelijk in mijn huis)
Als
- - de co2-niveaus overal lager zijn dan 800ppm, en
- - de vochtigheid in de badkamer is lager dan 65%, en
- - de lamp in het toilet is langer dan 5 minuten geleden uitgezet (ik wil de dat de ventilator nog 5 minuten doordraait nadat de persoon het toilet verlaten heeft)
dan moet de RPM weer naar 10% gaan.
Het licht in het toilet is een Tradfri lampje.
Ik ben zelf een HA-leek, kan ook niet programmeren. Ik heb ChatGPT een script laten schrijven. Het lijkt plausibel in mijn ogen, maar goed, plausibele maar complete verkeerde dingen maken is een specialiteit van ChatGPT
Als ik het script toevoeg in HA door een empty automation toe te voegen, en dan op 'edit in YAML' te klikken, dan krijg ik van HA de melding "Message malformed: extra keys not allowed @ data['0']"
Ik heb het ChatGPT 2x gevraagd, en de tweede scripts zijn helemaal anders. Bij beiden krijg ik dezelfde melding. Geen idee waarom, en wlk script beter zou zijn. Hebben jullie een idee?
Hieronder de twee versies.
YAML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
| - turn the ventilator RPM (entity ID sensor.duco_rpm) up to 60% when it detects CO2 levels over 1000ppm in one or more of the following sensors: sensor.le_e_carbon_dioxide, sensor.elio_carbon_dioxide, sensor.nina_carbon_dioxide, sensor.woonkamer_carbon_dioxide.
# This script will turn the ventilator RPM up to 60% when it detects CO2 levels over 1000ppm
# in one or more of the CO2 sensors in the bedroom, living room, and attic.
# When the CO2 levels drop below 700ppm, the ventilator RPM will be turned back to 10%.
# Also, when the humidity in the bathroom rises above 70%, the ventilator RPM will be turned to 60%.
# When the humidity drops below 65%, the RPM will be turned back to 10%.
# Additionally, when the toilet light is turned on for more than 1 minute, the ventilator RPM will be turned up to 60%.
# When the light is turned off, the RPM will be kept at 60% for 5 more minutes, after which it will drop back to 10%.
# First, we'll define the CO2 sensors, the humidity sensor, and the toilet light
co2_sensors:
- sensor.le_e_carbon_dioxide
- sensor.elio_carbon_dioxide
- sensor.nina_carbon_dioxide
- sensor.woonkamer_carbon_dioxide
humidity_sensor: sensor.lumi_lumi_weather_humidity
toilet_light: light.ikea_of_sweden_tradfribulbe27wwclear250lm_light
# Next, we'll define a function that checks if any of the CO2 sensors has a reading over 1000ppm
check_co2_levels:
sequence:
- condition:
state:
entity_id: "{% for sensor in co2_sensors %}{{sensor}}{% if not loop.last %},{% endif %}{% endfor %}"
above: 1000
action:
- event: script.turn_ventilator_rpm_up
# Now, we'll define a function that checks the humidity in the bathroom
check_bathroom_humidity:
sequence:
- condition:
state: "{{ humidity_sensor }}"
above: 70
action:
- event: script.turn_ventilator_rpm_up
# We'll also define a function that checks the state of the toilet light
check_toilet_light:
sequence:
- condition:
state: "{{ toilet_light }}"
duration: 1
value: "on"
action:
- event: script.turn_ventilator_rpm_up
- delay:
minutes: 5
continue_on_timeout: true
- service: fan.set_percentage
data:
entity_id: fan.open_duco
speed: 10%
# Now, we'll define the main part of the script, which will be executed whenever the conditions are met
turn_ventilator_rpm_up:
service: fan.set_percentage
data:
entity_id: fan.open_duco
speed: 60%
# Finally, we'll register the script as a Home Assistant automation
# so that it will be executed whenever the conditions are met
automation:
- alias: "Turn ventilator RPM up when CO2 levels are high"
trigger:
platform: time |
Ik heb het ChatGPT een tweede keer gevraagd, en toen kwam hij met dit op de proppen. Ziet er helemaal anders uit qua opbouw. Geen idee wat beter is.
YAML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
| - alias: Ventilator RPM - CO2 levels
trigger:
platform: numeric_state
entity_id:
- sensor.le_e_carbon_dioxide
- sensor.elio_carbon_dioxide
- sensor.nina_carbon_dioxide
- sensor.woonkamer_carbon_dioxide
above: 1000
condition:
- condition: numeric_state
entity_id: sensor.duco_rpm
below: 60
action:
- service: fan.set_speed
entity_id: fan.duco_ventilator
speed: 60
- alias: Ventilator RPM - CO2 levels (back to 10%)
trigger:
platform: numeric_state
entity_id:
- sensor.le_e_carbon_dioxide
- sensor.elio_carbon_dioxide
- sensor.nina_carbon_dioxide
- sensor.woonkamer_carbon_dioxide
below: 700
condition:
- condition: numeric_state
entity_id: sensor.duco_rpm
above: 10
action:
- service: fan.set_speed
entity_id: fan.duco_ventilator
speed: 10
- alias: Ventilator RPM - Bathroom humidity
trigger:
platform: numeric_state
entity_id: sensor.lumi_lumi_weather_humidity
above: 70
condition:
- condition: numeric_state
entity_id: sensor.duco_rpm
below: 60
action:
- service: fan.set_speed
entity_id: fan.duco_ventilator
speed: 60
- alias: Ventilator RPM - Bathroom humidity (back to 10%)
trigger:
platform: numeric_state
entity_id: sensor.lumi_lumi_weather_humidity
below: 65
condition:
- condition: numeric_state
entity_id: sensor.duco_rpm
above: 10
action:
- service: fan.set_speed
entity_id: fan.duco_ventilator
speed: 10
- alias: Ventilator RPM - Toilet light
trigger:
platform: state
entity_id: light.ikea_of_sweden_tradfribulbe27wwclear250lm_light
to: 'on'
for:
minutes: 1
action:
- service: fan.set_speed
entity_id: fan.duco_ventilator
speed: 60
- alias: Ventilator RPM - Toilet light (back to 10%)
trigger:
platform: state
entity_id: light.ikea_of_sweden_tradfribulbe27wwclear250lm_light
to: 'off'
action:
- delay: '00:05:00'
- service: fan.set_speed
entity_id: fan.duco_ventilator
speed: 10 |
[
Voor 0% gewijzigd door
Septillion op 18-12-2022 15:52
. Reden: Denk aan de 'yaml' bij de code tags aub! ]