Ramset
(Ramset)
December 21, 2022, 6:01pm
1
Hello,
I tried this Tutorial to create an Rain Sensor and for that i have to Invert the Status of the Doorsensor.
Tutorial
Open = Dry
Close = Rain
The Codesample in this Guide didnt work for me.
- platform: template
sensors:
regensensor:
friendly_name: "Regensensor"
device_class: moisture
icon_template: >-
{% if is_state('binary_sensor.fenster_turkontaktsensor_2', 'off') %}
mdi:weather-rainy
{% else %}
mdi:water-off
{% endif %}
My Version:
- platform: template
sensors:
regensensor:
friendly_name: "Regensensor"
device_class: moisture
icon_template: >-
{% if is_state('binary_sensor.lumi_lumi_sensor_magnet_aq2_opening', 'off') %}
mdi:weather-rainy
{% else %}
mdi:water-off
{% endif %}
Copy and Paste in this File: /config/sensors.yaml
Entetie: binary_sensor.lumi_lumi_sensor_magnet_aq2_opening
What i m doing wrong?
I can not program, I understand the subject only very rudimentary.
Thanks.
krskrab
December 21, 2022, 6:24pm
2
You added to configuration.yaml ?
sensor: !include sensor.yaml
Ramset
(Ramset)
December 21, 2022, 6:26pm
3
Sensor or Sensor"s" ?
My configuration.yaml:
# Loads default set of integrations. Do not remove.
default_config:
# Load frontend themes from the themes folder
frontend:
themes: !include_dir_merge_named themes
# Text to speech
tts:
- platform: google_translate
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml
camera:
- platform: generic
still_image_url: https://www.dwd.de/DWD/warnungen/warnstatus/SchilderHA.jpg
name: Wetter Warnungen
I tryd a other Version:
- platform: dwd_weather_warnings
name: Wetterwarnung Lohne
region_name: 803460006
- platform: template
sensors:
regensensor:
friendly_name: „Regensensor“
device_class: moisture
value_template: >-
{{ is_state("binary_sensor.lumi_lumi_sensor_magnet_aq2_opening", "off") }}
icon_template: >-
{% if is_state("binary_sensor.lumi_lumi_sensor_magnet_aq2_opening", "off") %}
mdi:weather-rainy
{% else %}
mdi:water-off
{% endif %}
than he said invalid
Invalid config for [sensor.template]: expected dictionary for dictionary value @ data['sensors']. Got None
extra keys not allowed @ data['regensensor']. Got OrderedDict([('friendly_name', '„Regensensor“'), ('device_class', 'moisture'), ('value_template', '{{ is_state(‚binary_sensor.lumi_lumi_sensor_magnet_aq2_opening‘, ‚off‘) }}'), ('icon_template', '{% if is_state(‚binary_sensor.lumi_lumi_sensor_magnet_aq2_opening‘, ‚off‘) %} mdi:weather-rainy {% else %} mdi:water-off {% endif %}')]). (See ?, line ?).
krskrab
December 21, 2022, 8:51pm
5
sensor.yaml
- platform: template
sensors:
regensensor:
friendly_name: "Regensensor"
device_class: moisture
value_template: >-
{{ is_state("binary_sensor.lumi_lumi_sensor_magnet_aq2_opening", "off") }}
icon_template: >-
{% if is_state("binary_sensor.lumi_lumi_sensor_magnet_aq2_opening", "off") %}
mdi:weather-rainy
{% else %}
mdi:water-off
{% endif %}
/
friendly_name: „Regensensor“
To
friendly_name: "Regensensor"
Ramset
(Ramset)
December 21, 2022, 9:06pm
6
Thank you very much for your answer.
I have done the following:
create an sensor.yaml
include that in den configuration yaml
copy your code (many thanks!) in it.
now i try to verify if it works. Please Wait
Forget my first Edit…
Thats what i see, i try to use it for an test.
Ramset
(Ramset)
December 21, 2022, 9:32pm
7
okay… now i feel stupid… very stupid. i thought all the time that the status at the actual sensor is overwritten… but i guess a new one is just created at which the inverted staus can be seen -.-"
Thank you very much!!! with your help I was able to solve the puzzle and the code from you also works!
I would not have managed without you!
In addition, I have learned something again today. But apart from that… you seem to have rebuilt your Home Assistant for a test, you have to take this time.
THANK YOU SO MUCH!
1 Like
Ramset
(Ramset)
December 21, 2022, 9:59pm
8
Can I ask for one last thing for advice? The status there is True and False. Can this be changed e.g. to Rain and Dry?
Edit:
Got it…
{{ "Regen" if is_state("binary_sensor.lumi_lumi_sensor_magnet_aq2_opening", "off") else "Trocken" }}
Complete Code for Copy and Paste:
- platform: template
sensors:
regensensor:
friendly_name: "Regensensor"
device_class: moisture
value_template: >-
{{ "Regen" if is_state("binary_sensor.lumi_lumi_sensor_magnet_aq2_opening", "off") else "Trocken" }}
icon_template: >-
{% if is_state("binary_sensor.lumi_lumi_sensor_magnet_aq2_opening", "off") %}
mdi:weather-rainy
{% else %}
mdi:water-off
{% endif %}