I am still new to HA and my knowledge of the yaml code is still limited. I would be thankful if anyone can help clean the the configuration file by creating yaml files for binary sensors and for other sensors. I tried creating them and included them in the configuration but keeps getting errors.
Here my code in the configuration.yaml:
# Freezer Monitoring
input_boolean:
freezer_power_supply_monitor_ib:
name: Freezer Power Supply Monitor (IB)
icon: mdi:power-plug-outline
freezer_unit_monitor_ib:
name: Freezer Unit Monitor (IB)
icon: mdi:thermometer-low
# Freezer sensor
template:
- binary_sensor:
- unique_id: freezer_running_monitor_bst
name: Freezer Running Monitor (BST)
icon: mdi:power
state: "{{states('sensor.zooz_zen15_power_cord_freezer_electric_consumption_v')|float > 50}}"
- binary_sensor:
- name: raub_home_wifi_tracker
state: >
{% if (states('sensor.raub_ssid') == "Casa") %} or ((states('sensor.raub_ssid') == "Games")) %}
home
{% else %}
not_home
{% endif %}
- binary_sensor:
- name: zak_wifigps
state: >
{% if (states('device_tracker.zak') == "Casa") %} or ((states('device_tracker.zak') == "Games")) %}
home
{% else %}
not_home
{% endif %}
- sensor:
- name: "Destination address"
state: >-
{%- if is_state("input_select.destination", "Home") -%}
725 5th Ave, New York, NY 10022, USA
{%- elif is_state("input_select.destination", "Work") -%}
767 5th Ave, New York, NY 10153, USA
{%- elif is_state("input_select.destination", "Parents") -%}
178 Broadway, Brooklyn, NY 11211, USA
{%- else -%}
Unknown
{%- endif %}
sensor:
- platform: template
sensors:
hvac_filter_days_remaining:
friendly_name: 'HVAC Filter Days remaining'
value_template: >
{{ states('input_number.hvac_filter_threshold') | int - (now() -
states( 'input_datetime.hvac_filter_last_replaced')
| as_datetime | as_local ).days }}
icon_template: mdi:clock-end
unit_of_measurement: 'Days'
- platform: template
sensors:
hvac_filter_days_since_replacement:
friendly_name: 'HVAC Filter Days Since Replaced'
value_template: >
{{ ((as_timestamp(now()) - state_attr('input_datetime.hvac_filter_last_replaced','timestamp')) | int / 86400) | round(0) -1 }}
icon_template: mdi:clock-end
unit_of_measurement: 'Days'
Like I said, I created a binary_sensor.yaml and copied the code posted in it. I included it in configuration using : binary_sensor: !include binary_sensor.yaml
Thank you in advance!
Thank you very much @pedolsky for taking time to explain this to me. Is there a way for me to recode the sensors in my current configuration yaml file so they can be all the same when I create their separate files. Instead of starting with template for example I would rename them binary_sensor?
@pedolsky . I successfully move the template sensors from the configuration file. However, I could not move the legacy sensors and keep getting error missing property “platform” in front sensor key. Could you please assist me in addressing this issue even with rewriting the sensor to meet the modern criteria? Thank you again.
Just my two cents but intentionally switching to something clearly marked legacy in the documentation isn’t really a good idea. Legacy means there are no new features or improvements coming (it’s already missing several key features such as trigger entity support, delay_on/delay_off, etc). It also means at some point in the future it will most likely no longer be supported at all and get removed although there’s no timeline for that date currently.
It seems like a particularly bad idea if you don’t know how to do it yourself as legacy things typically have reduced support. On encountering an issue with a legacy thing usually the first fix suggested is to not use the legacy thing. Legacy things are generally considered advanced for this reason alone.
If your whole goal is simply to put all sensors in one file why not just make a package called sensors and follow the instructions for packages I linked above? You can put config from any number of integrations in a package, doesn’t have to all be under sensor in configiration.yaml.
EDIT: actually just wrote out an example here for this if you are interested
@CentralCommand . Thank you Mike for taking time to reply to my concern. I agree with you that legacy sensors might not be supported in the future and for this reason, I want to replace the two mentioned here with the modern ones. I tried to modify the example shown at the template page but I got stuck at how at the command state:
# Example configuration entry
template:
- trigger:
- platform: time_pattern
# This will update every night
hours: 0
minutes: 0
sensor:
# Keep track how many days have past since a date
- name: "Not smoking"
state: '{{ ( ( as_timestamp(now()) - as_timestamp(strptime("06.07.2018", "%d.%m.%Y")) ) / 86400 ) | round(default=0) }}'
unit_of_measurement: "Days"