Help! I have split my switches into smaller YAML files and all good. But having a mare on teh sensors - a mix of template sensor and a binary RF mqtt sensor. It’s 0130hrs now here, so i have given up - hoping i may have some answers when i wake
Configuration.yam
sensor: !include_dir_list sensor/
I have a folder called sensor with the following three files. The first two give me no problem, appear in my states list.
platform: template
sensors:
next_dawn:
friendly_name: "Dawn"
value_template: >
{% set n = now().timestamp() %}
{% set sunrise = as_timestamp(state_attr("sun.sun" , "next_dawn") ) %}
{% set secondsToSunrise = sunrise - n %}
{% set hours = secondsToSunrise // 3600 %}
{% set secondsToSunrise = secondsToSunrise - ( hours * 3600 ) %}
{% set minutes = secondsToSunrise // 60 %}
{% set secondsToSunrise = secondsToSunrise - ( minutes * 60 ) %}
{{ '{:02}:{:02}:{:02}'.format(hours | int, minutes | int , secondsToSunrise | int) }}
The next one also works…
platform: template
sensors:
next_bin_colour:
friendly_name: "Next Bin Colour"
value_template: >
{% set week = now().strftime('%U') %}
{% set weekEven = (week | int) % 2 %}
{% if weekEven == 1%}BLUE{% else %}BLACK{% endif %}
but this one almost has me in tears - i just can’t get all three playing nicely…
It complains about various things - sometimes i can’t have on/off for payload. Other times i can’t have mapping if i move the ‘binary_sensor’ line. i had these three wokring in configuratoin.yaml - but struggling to break them outinto the sensors/ folder. I think it’s to do with a mix of sensor types or platform types - but my head is now full.
any help much appreciated - sorry for long post - but i am still new at this YAML stuff so wanted to give as much info as possible. Have also tried with include_dir_merge_list as well.
That’s because sensor: and binary_sensor: need their own lines in your config.yaml, and in your case, their own files. It sounds like what you really want is to be using packages.
My config looks like this:
packages: !include_dir_named packages
and then I have a folder called packages where I have various YAML files in various sub-folders. Each file can have one heading of each entity type.
Packages are an option like Steve said, or you could add binary_sensor: to your configuration.yaml with an !include_* reference there. My GitHub has an example of this if you wanna take a look.
Malcolm, once again, none of these sensors will update because they do not use an entity that HA will recognise to require updating.
I assume that once again you are using nodered to trigger updates ?
for the sunrise one why don’t you use the standard ? : -
Change the format as you see fit (this will update)
EDIT : SORRY, just re-read you need a count down to the next sunrise.
Just subtract now().timestamp() from the sunrise and timestamp custom it to your preferred format.
The template still won’t update until it sees the next sunrise time is different (ie at sunrise)
Hey Mutt. I’ve just removed NodeRed now - and sticking with basics - pointless running when I can barely walk through HA at the moment. So messing with configs, nested configs - just understanding the very basics. Getting my RF bridge up, recognising the keyfobs etc., Zero automatoin currently. And yes, since killing NodeRed my tempalte sensors dont’ update on teh dashboard - but i will work my way around to that ( hopefully ).
I am not in a hurry with this, so I do have time on my side. And thanks for the simplified format - really appreciated - will drop that in.
I endorse Steve’s suggestion for packages.
Tediore’s suggestion works but imagine (say) writing an alarm clock ; -
You need an input_boolean so go to the input boolean file to add one
You need an input datetime so go to the input datetime file to add one
You need a binary sensor so go to the binary sensor file to add one
You need an automation so go to the automations file to add one
Etc.
Still, some people prefer to do it this way.
The alternative is to store it all in your main configuration.yaml file ( it gets big really quick).
Packages, if I want to give you an alarm clock I send you one file and it’s done. (as long as the entities are unique). If you want to edit your alarm clock it’s all in one package (file)
I’m gonna convince Tediore yet. And when I do I’ll steal ALL his work and say : - “I made this !” (in joke)
packages make sense then - but i will stick with the individuals for now until i have my head around it. then i will move to packages as it seems sensible. Tonight’s task is pushing an MQTT message to the RF bridge to switch on a device connected via an RF socket. See how this goes :).