Skip to content

Instantly share code, notes, and snippets.

@adrianmihalko
Created March 9, 2022 16:59
Show Gist options
  • Save adrianmihalko/9829aa307ff78aede02a4cf1eefe103e to your computer and use it in GitHub Desktop.
Save adrianmihalko/9829aa307ff78aede02a4cf1eefe103e to your computer and use it in GitHub Desktop.
# Basic sensor, read everything from MQTT
- platform: mqtt
name: "WLANThermo"
# change topic to your modelname!
state_topic: "WLanThermo/NANOv3/status/data"
value_template: "{{ value_json.system.soc }}"
# change topic to your modelname!
json_attributes_topic: "WLanThermo/NANOv3/status/data"
json_attributes_template: "{{ value_json | tojson }}"
device_class: battery
unit_of_measurement: "%"
expire_after: 60
# Template sensor per channel
- platform: template
sensors:
wlanthermo_pitmaster_all:
value_template: "{{ state_attr('sensor.wlanthermo', 'pitmaster') }}"
entity_id: sensor.wlanthermo
wlanthermo_pitmaster_value:
friendly_name: "Pitmaster"
# set to zero if wlanthermo is turned off or channel not plugged in
value_template: >
{% if not is_state('sensor.wlanthermo', 'unknown') %}
{% set value = state_attr('sensor.wlanthermo', 'pitmaster')['pm'][0]['value'] %}
{% if value >= 0 and value <= 100 %}
{{ value }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
unit_of_measurement: "%"
entity_id: sensor.wlanthermo
wlanthermo_pitmaster_channel:
friendly_name: "Channel"
# set to zero if wlanthermo is turned off or channel not plugged in
value_template: >
{% if not is_state('sensor.wlanthermo', 'unknown') %}
{% set channel = state_attr('sensor.wlanthermo', 'pitmaster')['pm'][0]['channel'] %}
{% if channel >= 1 and channel <= 6 %}
{{ channel }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
unit_of_measurement: ""
entity_id: sensor.wlanthermo
wlanthermo_pitmaster_mode:
friendly_name: "Mode"
# set to zero if wlanthermo is turned off or channel not plugged in
value_template: >
{% if not is_state('sensor.wlanthermo', 'unknown') %}
{% set typ = state_attr('sensor.wlanthermo', 'pitmaster')['pm'][0]['typ'] %}
{{ typ }}
{% else %}
0
{% endif %}
unit_of_measurement: ""
entity_id: sensor.wlanthermo
# Template sensor per channel
- platform: template
sensors:
# Channel 1
wlanthermo_channel_1_all:
value_template: "{{ state_attr('sensor.wlanthermo', 'channel')[0] }}"
entity_id: sensor.wlanthermo
wlanthermo_channel_1:
friendly_name: "Channel 1"
# set to zero if wlanthermo is turned off or channel not plugged in
value_template: >
{% if not is_state('sensor.wlanthermo', 'unknown') %}
{% set temp = state_attr('sensor.wlanthermo', 'channel')[0]['temp'] %}
{% if temp >= -30 and temp <= 300 %}
{{ temp }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
unit_of_measurement: "°C"
device_class: temperature
entity_id: sensor.wlanthermo
# Channel 2
wlanthermo_channel_2_all:
value_template: "{{ state_attr('sensor.wlanthermo', 'channel')[1] }}"
entity_id: sensor.wlanthermo
wlanthermo_channel_2:
friendly_name: "Channel 2"
# set to zero if wlanthermo is turned off or channel not plugged in
value_template: >
{% if not is_state('sensor.wlanthermo', 'unknown') %}
{% set temp = state_attr('sensor.wlanthermo', 'channel')[1]['temp'] %}
{% if temp >= -30 and temp <= 300 %}
{{ temp }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
unit_of_measurement: "°C"
device_class: temperature
entity_id: sensor.wlanthermo
# Channel 3
wlanthermo_channel_3_all:
value_template: "{{ state_attr('sensor.wlanthermo', 'channel')[2] }}"
entity_id: sensor.wlanthermo
wlanthermo_channel_3:
friendly_name: "Channel 3"
# set to zero if wlanthermo is turned off or channel not plugged in
value_template: >
{% if not is_state('sensor.wlanthermo', 'unknown') %}
{% set temp = state_attr('sensor.wlanthermo', 'channel')[2]['temp'] %}
{% if temp >= -30 and temp <= 300 %}
{{ temp }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
unit_of_measurement: "°C"
device_class: temperature
entity_id: sensor.wlanthermo
# Channel 4
wlanthermo_channel_4_all:
value_template: "{{ state_attr('sensor.wlanthermo', 'channel')[3] }}"
entity_id: sensor.wlanthermo
wlanthermo_channel_4:
friendly_name: "Channel 4"
# set to zero if wlanthermo is turned off or channel not plugged in
value_template: >
{% if not is_state('sensor.wlanthermo', 'unknown') %}
{% set temp = state_attr('sensor.wlanthermo', 'channel')[3]['temp'] %}
{% if temp >= -30 and temp <= 300 %}
{{ temp }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
unit_of_measurement: "°C"
device_class: temperature
entity_id: sensor.wlanthermo
# Channel 5
wlanthermo_channel_11_all:
value_template: "{{ state_attr('sensor.wlanthermo', 'channel')[10] }}"
entity_id: sensor.wlanthermo
wlanthermo_channel_11:
friendly_name: "Meater"
# set to zero if wlanthermo is turned off or channel not plugged in
value_template: >
{% if not is_state('sensor.wlanthermo', 'unknown') %}
{% set temp = state_attr('sensor.wlanthermo', 'channel')[10]['temp'] %}
{% if temp >= -30 and temp <= 300 %}
{{ temp }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
unit_of_measurement: "°C"
device_class: temperature
entity_id: sensor.wlanthermo
# Channel 6
wlanthermo_channel_12_all:
value_template: "{{ state_attr('sensor.wlanthermo', 'channel')[11] }}"
entity_id: sensor.wlanthermo
wlanthermo_channel_12:
friendly_name: "Meater_outside"
# set to zero if wlanthermo is turned off or channel not plugged in
value_template: >
{% if not is_state('sensor.wlanthermo', 'unknown') %}
{% set temp = state_attr('sensor.wlanthermo', 'channel')[11]['temp'] %}
{% if temp >= -30 and temp <= 300 %}
{{ temp }}
{% else %}
0
{% endif %}
{% else %}
0
{% endif %}
unit_of_measurement: "°C"
device_class: temperature
entity_id: sensor.wlanthermo
#Now we need to define input_number elements, so that we are able to control a slider in the UI.
input_number:
wlanthermo_channel_1_min:
name: Channel 1 min
min: 0
max: 250
step: 1
unit_of_measurement: °C
icon: mdi:thermometer-low
wlanthermo_channel_1_max:
name: Channel 1 max
min: 0
max: 250
step: 1
unit_of_measurement: °C
icon: mdi:thermometer-high
wlanthermo_channel_2_min:
name: Channel 2 min
min: 0
max: 250
step: 1
unit_of_measurement: °C
icon: mdi:thermometer-low
wlanthermo_channel_2_max:
name: Channel 2 max
min: 0
max: 250
step: 1
unit_of_measurement: °C
icon: mdi:thermometer-high
wlanthermo_channel_3_min:
name: Channel 3 min
min: 0
max: 250
step: 1
unit_of_measurement: °C
icon: mdi:thermometer-low
wlanthermo_channel_3_max:
name: Channel 3 max
min: 0
max: 250
step: 1
unit_of_measurement: °C
icon: mdi:thermometer-high
wlanthermo_channel_4_min:
name: Channel 4 min
min: 0
max: 250
step: 1
unit_of_measurement: °C
icon: mdi:thermometer-low
wlanthermo_channel_4_max:
name: Channel 4 max
min: 0
max: 250
step: 1
unit_of_measurement: °C
icon: mdi:thermometer-high
wlanthermo_channel_11_min:
name: Channel 11 min
min: 0
max: 250
step: 1
unit_of_measurement: °C
icon: mdi:thermometer-low
wlanthermo_channel_11_max:
name: Channel 11 max
min: 0
max: 250
step: 1
unit_of_measurement: °C
icon: mdi:thermometer-high
wlanthermo_channel_12_min:
name: Channel 12 min
min: 0
max: 250
step: 1
unit_of_measurement: °C
icon: mdi:thermometer-low
wlanthermo_channel_12_max:
name: Channel 12 max
min: 0
max: 250
step: 1
unit_of_measurement: °C
icon: mdi:thermometer-high
wlanthermo_pitmaster_temp:
name: Set temperatur
min: 0
max: 250
step: 1
unit_of_measurement: °C
icon: mdi:thermometer
input_select:
wlanthermo_pitmaster_mode:
name: Mode
options:
- 'Off'
- 'Automatic'
icon: mdi:fan
wlanthermo_pitmaster_channel:
name: Channel
options:
- '1'
- '2'
- '3'
- '4'
- '11'
- '12'
icon: mdi:pound
wlanthermo_channel_1_alarm:
name: Notification
options:
- 'Off'
- 'On'
icon: mdi:thermometer-alert
wlanthermo_channel_2_alarm:
name: Notification
options:
- 'Off'
- 'On'
icon: mdi:thermometer-alert
wlanthermo_channel_3_alarm:
name: Notification
options:
- 'Off'
- 'On'
icon: mdi:thermometer-alert
wlanthermo_channel_4_alarm:
name: Notification
options:
- 'Off'
- 'On'
icon: mdi:thermometer-alert
wlanthermo_channel_11_alarm:
name: Notification
options:
- 'Off'
- 'On'
icon: mdi:thermometer-alert
wlanthermo_channel_12_alarm:
name: Notification
options:
- 'Off'
- 'On'
icon: mdi:thermometer-alert
automation:
#Automations (updating sensor values)
#In the automations you have to define how to set the defined input_number elements (we want to use the values which #are coming from MQTT) and what to do if someone changes the slider in the UI (we want to update the WLANThermo).
## First automation: set Home Assistant sensor value from MQTT messages, so we
# update if someone changes the values on web interface
- id: '1565774399160'
alias: WLANThermo update channels min/max from MQTT
trigger:
- entity_id: sensor.wlanthermo
platform: state
condition: []
action:
- data_template:
entity_id: input_number.wlanthermo_channel_1_min
value: '{{ state_attr(''sensor.wlanthermo'', ''channel'').0.min }}'
service: input_number.set_value
- data_template:
entity_id: input_number.wlanthermo_channel_1_max
value: '{{ state_attr(''sensor.wlanthermo'', ''channel'').0.max }}'
service: input_number.set_value
- data_template:
entity_id: input_number.wlanthermo_channel_2_min
value: '{{ state_attr(''sensor.wlanthermo'', ''channel'').1.min }}'
service: input_number.set_value
- data_template:
entity_id: input_number.wlanthermo_channel_2_max
value: '{{ state_attr(''sensor.wlanthermo'', ''channel'').1.max }}'
service: input_number.set_value
- data_template:
entity_id: input_number.wlanthermo_channel_3_min
value: '{{ state_attr(''sensor.wlanthermo'', ''channel'').2.min }}'
service: input_number.set_value
- data_template:
entity_id: input_number.wlanthermo_channel_3_max
value: '{{ state_attr(''sensor.wlanthermo'', ''channel'').2.max }}'
service: input_number.set_value
- data_template:
entity_id: input_number.wlanthermo_channel_4_min
value: '{{ state_attr(''sensor.wlanthermo'', ''channel'').3.min }}'
service: input_number.set_value
- data_template:
entity_id: input_number.wlanthermo_channel_4_max
value: '{{ state_attr(''sensor.wlanthermo'', ''channel'').3.max }}'
service: input_number.set_value
- data_template:
entity_id: input_number.wlanthermo_channel_11_min
value: '{{ state_attr(''sensor.wlanthermo'', ''channel'').10.min }}'
service: input_number.set_value
- data_template:
entity_id: input_number.wlanthermo_channel_11_max
value: '{{ state_attr(''sensor.wlanthermo'', ''channel'').10.max }}'
service: input_number.set_value
- data_template:
entity_id: input_number.wlanthermo_channel_12_min
value: '{{ state_attr(''sensor.wlanthermo'', ''channel'').11.min }}'
service: input_number.set_value
- data_template:
entity_id: input_number.wlanthermo_channel_12_max
value: '{{ state_attr(''sensor.wlanthermo'', ''channel'').11.max }}'
service: input_number.set_value
- data_template:
entity_id: input_number.wlanthermo_pitmaster_temp
value: '{{ state_attr(''sensor.wlanthermo'', ''pitmaster'').pm.0.set }}'
service: input_number.set_value
- data_template:
entity_id: input_select.wlanthermo_pitmaster_mode
option: '{{ state_attr(''sensor.wlanthermo'', ''pitmaster'').pm.0.typ | replace(''off'',''Off'') | replace(''auto'',''Automatisch'') }}'
service: input_select.select_option
- data_template:
entity_id: input_select.wlanthermo_pitmaster_channel
option: '{{ state_attr(''sensor.wlanthermo'', ''pitmaster'').pm.0.channel }}'
service: input_select.select_option
- data_template:
entity_id: input_select.wlanthermo_channel_1_alarm
option: '{{ state_attr(''sensor.wlanthermo'', ''channel'').0.alarm | replace(''0'',''Off'') | replace(''1'',''On'') }}'
service: input_select.select_option
- data_template:
entity_id: input_select.wlanthermo_channel_2_alarm
option: '{{ state_attr(''sensor.wlanthermo'', ''channel'').1.alarm | replace(''0'',''Off'') | replace(''1'',''On'') }}'
service: input_select.select_option
- data_template:
entity_id: input_select.wlanthermo_channel_3_alarm
option: '{{ state_attr(''sensor.wlanthermo'', ''channel'').2.alarm | replace(''0'',''Off'') | replace(''1'',''On'') }}'
service: input_select.select_option
- data_template:
entity_id: input_select.wlanthermo_channel_4_alarm
option: '{{ state_attr(''sensor.wlanthermo'', ''channel'').3.alarm | replace(''0'',''Off'') | replace(''1'',''On'') }}'
service: input_select.select_option
- data_template:
entity_id: input_select.wlanthermo_channel_11_alarm
option: '{{ state_attr(''sensor.wlanthermo'', ''channel'').10.alarm | replace(''0'',''Off'') | replace(''1'',''On'') }}'
service: input_select.select_option
- data_template:
entity_id: input_select.wlanthermo_channel_12_alarm
option: '{{ state_attr(''sensor.wlanthermo'', ''channel'').11.alarm | replace(''0'',''Off'') | replace(''1'',''On'') }}'
service: input_select.select_option
- id: '1565867288673'
alias: WLANThermo set channel 1 min
trigger:
- entity_id: input_number.wlanthermo_channel_1_min
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":1,"min":''+states(''input_number.wlanthermo_channel_1_min'')+''}''
}}'
- id: '1565867288674'
alias: WLANThermo set channel 1 max
trigger:
- entity_id: input_number.wlanthermo_channel_1_max
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":1,"max":''+states(''input_number.wlanthermo_channel_1_max'')+''}''
}}'
- id: '1565867288675'
alias: WLANThermo set channel 2 min
trigger:
- entity_id: input_number.wlanthermo_channel_2_min
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":2,"min":''+states(''input_number.wlanthermo_channel_2_min'')+''}''
}}'
- id: '1565867288676'
alias: WLANThermo set channel 2 max
trigger:
- entity_id: input_number.wlanthermo_channel_2_max
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":2,"max":''+states(''input_number.wlanthermo_channel_2_max'')+''}''
}}'
- id: '1565867288677'
alias: WLANThermo set channel 3 min
trigger:
- entity_id: input_number.wlanthermo_channel_3_min
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":3,"min":''+states(''input_number.wlanthermo_channel_3_min'')+''}''
}}'
- id: '1565867288678'
alias: WLANThermo set channel 3 max
trigger:
- entity_id: input_number.wlanthermo_channel_3_max
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":3,"max":''+states(''input_number.wlanthermo_channel_3_max'')+''}''
}}'
- id: '1565867288679'
alias: WLANThermo set channel 4 min
trigger:
- entity_id: input_number.wlanthermo_channel_4_min
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":4,"min":''+states(''input_number.wlanthermo_channel_4_min'')+''}''
}}'
- id: '1565867288680'
alias: WLANThermo set channel 4 max
trigger:
- entity_id: input_number.wlanthermo_channel_4_max
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":4,"max":''+states(''input_number.wlanthermo_channel_4_max'')+''}''
}}'
- id: '1565867288681'
alias: WLANThermo set channel 11 min
trigger:
- entity_id: input_number.wlanthermo_channel_11_min
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":11,"min":''+states(''input_number.wlanthermo_channel_11_min'')+''}''
}}'
- id: '1565867288682'
alias: WLANThermo set channel 11 max
trigger:
- entity_id: input_number.wlanthermo_channel_11_max
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":11,"max":''+states(''input_number.wlanthermo_channel_11_max'')+''}''
}}'
- id: '1565867288683'
alias: WLANThermo set channel 12 min
trigger:
- entity_id: input_number.wlanthermo_channel_12_min
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":12,"min":''+states(''input_number.wlanthermo_channel_12_min'')+''}''
}}'
- id: '1565867288684'
alias: WLANThermo set channel 12 max
trigger:
- entity_id: input_number.wlanthermo_channel_12_max
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":12,"max":''+states(''input_number.wlanthermo_channel_12_max'')+''}''
}}'
- id: '1565867288685'
alias: WLANThermo set pitmaster temp
trigger:
- entity_id: input_number.wlanthermo_pitmaster_temp
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/pitmaster
retain: true
payload: '{{ ''[{"id":0,"channel":''+states(''input_select.wlanthermo_pitmaster_channel'')+'',"pid":2,"value":0,"set":''+states(''input_number.wlanthermo_pitmaster_temp'')+'',"typ":''+states(''input_select.wlanthermo_pitmaster_mode'') | replace(''Off'',''off'') | replace(''Automatisch'',''auto'')+''}]''}}'
- id: '1565867288686'
alias: WLANThermo set pitmaster channel
trigger:
- entity_id: input_select.wlanthermo_pitmaster_channel
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/pitmaster
retain: true
payload: '{{ ''[{"id":0,"channel":''+states(''input_select.wlanthermo_pitmaster_channel'')+'',"pid":2,"value":0,"set":''+states(''input_number.wlanthermo_pitmaster_temp'')+'',"typ":''+states(''input_select.wlanthermo_pitmaster_mode'') | replace(''Off'',''off'') | replace(''Automatisch'',''auto'')+''}]''}}'
- id: '1565867288687'
alias: WLANThermo set pitmaster mode
trigger:
- entity_id: input_select.wlanthermo_pitmaster_mode
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/pitmaster
retain: true
payload: '{{ ''[{"id":0,"channel":''+states(''input_select.wlanthermo_pitmaster_channel'')+'',"pid":2,"value":0,"set":''+states(''input_number.wlanthermo_pitmaster_temp'')+'',"typ":''+states(''input_select.wlanthermo_pitmaster_mode'') | replace(''Off'',''off'') | replace(''Automatisch'',''auto'')+''}]''}}'
- id: '1565867288688'
alias: WLANThermo set channel 1 alarm
trigger:
- entity_id: input_select.wlanthermo_channel_1_alarm
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":1,"alarm":''+states(''input_select.wlanthermo_channel_1_alarm'') | replace(''Off'',''0'') | replace(''On'',''1'')+''}''}}'
- id: '1565867288689'
alias: WLANThermo set channel 2 alarm
trigger:
- entity_id: input_select.wlanthermo_channel_2_alarm
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":2,"alarm":''+states(''input_select.wlanthermo_channel_2_alarm'') | replace(''Off'',''0'') | replace(''On'',''1'')+''}''}}'
- id: '1565867288690'
alias: WLANThermo set channel 3 alarm
trigger:
- entity_id: input_select.wlanthermo_channel_3_alarm
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":3,"alarm":''+states(''input_select.wlanthermo_channel_3_alarm'') | replace(''Off'',''0'') | replace(''On'',''1'')+''}''}}'
- id: '1565867288691'
alias: WLANThermo set channel 4 alarm
trigger:
- entity_id: input_select.wlanthermo_channel_4_alarm
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":4,"alarm":''+states(''input_select.wlanthermo_channel_4_alarm'') | replace(''Off'',''0'') | replace(''On'',''1'')+''}''}}'
- id: '1565867288692'
alias: WLANThermo set channel 11 alarm
trigger:
- entity_id: input_select.wlanthermo_channel_11_alarm
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":11,"alarm":''+states(''input_select.wlanthermo_channel_11_alarm'') | replace(''Off'',''0'') | replace(''On'',''1'')+''}''}}'
- id: '1565867288693'
alias: WLANThermo set channel 12 alarm
trigger:
- entity_id: input_select.wlanthermo_channel_12_alarm
platform: state
condition: []
action:
- service: mqtt.publish
data_template:
topic: WLanThermo/WlanThermo/set/channels
retain: true
payload: '{{ ''{"number":12,"alarm":''+states(''input_select.wlanthermo_channel_12_alarm'') | replace(''Off'',''0'') | replace(''On'',''1'')+''}''}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment