Skip to content

Instantly share code, notes, and snippets.

@golles
Last active April 14, 2023 07:47
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save golles/ae32d9a7c14b63d9d68f6ff9a6fd4d6a to your computer and use it in GitHub Desktop.
Save golles/ae32d9a7c14b63d9d68f6ff9a6fd4d6a to your computer and use it in GitHub Desktop.
Mechanische ventilatie in Home Assistant

Allereerst bedankt @eelcohn voor je prachtige project --> https://github.com/eelcohn/nRF905-API

Als je packages gebruikt, zou het makkelijk zijn om dit te kopieren naar jouw HA. Anders zou je de elementen in zehnder.yaml handmatig moeten kopieren naar je configuration.yaml.

Hoe werkt het?

Een rest sensor (sensor.mechanische_ventilatie_status) haalt de data van de api en een fan template maakt er vervolgens een fan entity van (fan.mechanische_ventilatie). Op deze manier krijg je out of the box een speed list in lovelace en bijbehorende services.

De individuele rest commands worden gewrapt door scripts, dit zodat de host uit secrets kan komen, helaas is er geen manier om een secret in een template toe te passen. Fan templates moeten verplicht een turn_on en turn_off hebben, dit heeft de mechanische ventilatie niet, nu roepen deze acties een dummy script ventilation_turn_on_off_dummy aan die niks doet (als iemand hier een ander idee voor heeft, hoor ik het graag).

Let op

json_attributes_path is anders voor iedereen, deze moet je aanpassen. De card gebruikt custom:multiple-entity-row.

type: entities
show_header_toggle: false
entities:
- entity: fan.mechanische_ventilatie
- type: custom:multiple-entity-row
entity: sensor.mechanische_ventilatie_status
attribute: speed
name: Stand
icon: mdi:speedometer
entities:
- entity: sensor.mechanische_ventilatie_status
icon: mdi:fan-speed-1
name: Laag
tap_action:
action: call-service
service: script.ventilation_set_preset_mode
service_data:
preset_mode: low
- entity: sensor.mechanische_ventilatie_status
icon: mdi:fan-speed-2
name: Medium
tap_action:
action: call-service
service: script.ventilation_set_preset_mode
service_data:
preset_mode: medium
- entity: sensor.mechanische_ventilatie_status
icon: mdi:fan-speed-3
name: Hoog
tap_action:
action: call-service
service: script.ventilation_set_preset_mode
service_data:
preset_mode: high
- type: custom:multiple-entity-row
entity: sensor.mechanische_ventilatie_status
attribute: timer
name: Timer
icon: mdi:timer
entities:
- entity: sensor.mechanische_ventilatie_status
icon: mdi:clock-time-two-outline
name: 10m
tap_action:
action: call-service
service: script.ventilation_set_speed_timer
service_data:
speed: high
timer: 10
- entity: sensor.mechanische_ventilatie_status
icon: mdi:clock-time-six-outline
name: 30m
tap_action:
action: call-service
service: script.ventilation_set_speed_timer
service_data:
speed: high
timer: 30
- entity: sensor.mechanische_ventilatie_status
icon: mdi:clock-time-twelve-outline
name: 60m
tap_action:
action: call-service
service: script.ventilation_set_speed_timer
service_data:
speed: high
timer: 60
- type: attribute
entity: sensor.mechanische_ventilatie_status
attribute: percentage
name: Percentage
icon: mdi:percent-outline
suffix: '%'
- type: attribute
entity: sensor.mechanische_ventilatie_status
attribute: voltage
name: Voltage
icon: mdi:flash
suffix: v
# Mechanische ventilatie (nrf905)
nrf905_username: user
nrf905_password: pass
nrf905_host: a.b.c.d
nrf905_status_url: http://a.b.c.d/api/test/fan/querydevice.json
fan:
- platform: template
fans:
mechanische_ventilatie:
friendly_name: Mechanische ventilatie
value_template: >
{{ states('sensor.mechanische_ventilatie_status') }}
availability_template: >
{{ states('sensor.mechanische_ventilatie_status') }}
percentage_template: >
{{ state_attr('sensor.mechanische_ventilatie_status', 'percentage') }}
preset_mode_template: >
{{ state_attr('sensor.mechanische_ventilatie_status', 'speed') }}
turn_on:
service: script.ventilation_turn_on_off_dummy
turn_off:
service: script.ventilation_turn_on_off_dummy
set_percentage:
service: script.ventilation_set_voltage
data:
voltage: '{{ percentage / 10 }}'
set_preset_mode:
service: script.ventilation_set_preset_mode
data:
preset_mode: '{{ preset_mode }}'
preset_modes:
- low
- medium
- high
- max
sensor:
- platform: rest
name: Mechanische ventilatie status
resource: !secret nrf905_status_url
username: !secret nrf905_username
password: !secret nrf905_password
value_template: >
{% if value_json['result'] == 'ok' %}
on
{% else %}
off
{% endif %}
json_attributes_path: $.devices.C0 # This will be different for each fan.
json_attributes:
- voltage
- percentage
- speed
- timer
script:
ventilation_turn_on_off_dummy:
mode: single
sequence:
- delay: 1
ventilation_set_preset_mode:
mode: single
fields:
host:
description: Hostname or ip
preset_mode:
description: Set the fan preset mode (low/medium/high/max)
sequence:
- service: rest_command.ventilation_preset_mode
data:
host: !secret nrf905_host
preset_mode: '{{ preset_mode }}'
- delay: 1
- service: homeassistant.update_entity
data:
entity_id: sensor.mechanische_ventilatie_status
ventilation_set_speed_timer:
mode: single
fields:
host:
description: Hostname or ip
speed:
description: Set the fan speed (low/medium/high/max)
timer:
description: Set the fan timer (number of minutes)
sequence:
- service: rest_command.ventilation_set_speed_timer
data:
host: !secret nrf905_host
speed: '{{ speed }}'
timer: '{{ timer }}'
- delay: 1
- service: homeassistant.update_entity
data:
entity_id: sensor.mechanische_ventilatie_status
ventilation_set_voltage:
mode: single
fields:
host:
description: Hostname or ip
voltage:
description: Set the fan voltage, between 0.0 and 10.0
sequence:
- service: rest_command.ventilation_set_voltage
data:
host: !secret nrf905_host
voltage: '{{ voltage }}'
- delay: 1
- service: homeassistant.update_entity
data:
entity_id: sensor.mechanische_ventilatie_status
rest_command:
ventilation_preset_mode:
url: http://{{ host }}/api/v2/fan/setspeed.json?speed={{ preset_mode }}
username: !secret nrf905_username
password: !secret nrf905_password
ventilation_set_speed_timer:
url: http://{{ host }}/api/v2/fan/setspeed.json?speed={{ speed }}&timer={{ timer }}
username: !secret nrf905_username
password: !secret nrf905_password
ventilation_set_voltage:
url: http://{{ host }}/api/v2/fan/setvoltage.json?voltage={{ voltage }}
username: !secret nrf905_username
password: !secret nrf905_password
@xirixiz
Copy link

xirixiz commented Jan 28, 2021

Thanks! Ik gebruik dit voor json_attributes_path:

json_attributes_path: "$.devices.*"

Dat zou voor de meeste mensen moeten werken. Werkt het niet dan kan je het ID achterhalen met curl en jq:

curl -Ssl -u <user>:<pass> http://192.168.x.x/api/test/fan/querydevice.json | jq -r '.devices[]'

Of alleen het ID:

curl -Ssl -u <user>:<pass> http://192.168.x.x/api/test/fan/querydevice.json | jq -r '.devices[].id'

@robbinonline
Copy link

Werkt perfect, dank!

@golles
Copy link
Author

golles commented Dec 30, 2022

Werkt perfect, dank!

Ik gebruik dit zelf niet meer, ben een overgestapt op https://github.com/Sanderhuisman/ESPHome-Zehnder-RF

@robbinonline
Copy link

Nog beter gelijk gemigreerd, dank!

@xirixiz
Copy link

xirixiz commented Jan 1, 2023

Mooi idd. Ik gebruik dit ook al een tijd niet meer.

Zelf heb ik een esp rechtstreeks aangesloten en gebruik ik een hue sensor om te schakelen.
Dat werkt al tijden stabiel!

https://gist.github.com/SqyD/38d10391c2e21988406d2bdaec24f031?permalink_comment_id=3969926

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment