Templatesensor custom_component

Three cheers for @ludeeus !!!

This custom_component allows you to create template sensors entirely in the UI and those sensors are available to use without a restart.

Home Assistant has LONG needed the ability to add template sensors without a restart.

My Wishlist:

  • the same thing for template binary_sensors
  • allow for editing and reloading via yaml (instead of just GUI)
1 Like

When I get the time to test it properly I will probably create one for binary_sensor as well (if someone does not beat me to it.

As for yaml, that will not work at all, the reason we can do this when it’s added in the UI is because of the magic behind config entries :slight_smile:


Ahhh. That makes sense about YAML. Still, absolutely wonderful!

Here’s my first take at templatebinarysensor

That was fast :smiley:
I know there is at least one issue with it (It updates every 30 sec, and not just when needed)

Nice work!

Is it possible to add attributes to the template sensor?
If not, then please consider the functionality.



Please open a Feature Request here https://github.com/custom-components/templatesensor where you describe how that should be done.

I tried doing it, but it ended up way to advanced for anyone to use, so it was removed before the initial release.

@ludeeus because of the way config_flow works, it’s not possible to EDIT a templatesensor, right?


You have to delete then add a new one, if you give the new one the same name the history is kept.

If you don’t remember the template you had, you can see it in .storage/core.config_entries
NB! Do not edit that file, only copy from it!

1 Like

Yeah… I think your templatesensor works the same way, yes? I basically just copied your code and changed the bits that needed to be changed to support a binary_sensor. I would prefer it update immediately, but only when needed, of course. So I’ll work on that next.

Correct :slight_smile:

Like I said , I have not had the time til test it fully yet, just know that is one of the issues with it.
I think something like subscribing to all state changes could be doable, but require some testing.



1 Like

I guess I need to see how you did that and update mine to do the same. That’s awesome!

1 Like

It should work with 0.98+, but I have only tested it with 0.99.0dev

any plans to get these integrated into home assistant? it appears to me to be a core feature.

Thank you for this and thank you @ludeeus !

I actually managed (new to HA) to install both repositories through HACS. The templatesensor one I can “open” from UI → Configuration → + and search for it. But sadly the templatebinarysensor I can not find through this way.

Restarted (even rebooted Rpi3b+) several times.

I’m running v 6.5 of HA and core-2021.10.6

Grateful for any idea where I can start to look!

Your log file will tell you why.
Hint: this is needed https://github.com/dlashua/templatebinarysensor/pull/1

Thank you for your reply, I really appreciate it.

I checked supervisor → system → logg, but saw nothing strange. But after your post I learned that I could pull logs from “core” and there it was:

2021-11-11 12:50:00 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration templatebinarysensor which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-11-11 12:50:00 ERROR (SyncWorker_1) [homeassistant.loader] The custom integration ‘templatebinarysensor’ does not have a version key in the manifest file and was blocked from loading. See Custom integration changes | Home Assistant Developer Docs for more details

I did try before to put my version of HA in the manifest.json of templatebinarysensor:

Didn’t change anything though, so I guess I have misunderstood some (or a lot) things.

Think I got it now, my manifest.json for (templatebinarysensor) looks like this:

“domain”: “templatebinarysensor”,
“name”: “UI Template binary_sensor configuration”,
“version”: “0.0.2”,
“documentation”: “GitHub - dlashua/templatebinarysensor: Add template binary_sensors from the UI.”,
“dependencies”: ,
“config_flow”: true,
“codeowners”: [
“requirements”: ,
“homeassistant”: “0.96.0”

Restarted HA, but still not able to find the integration when searching through configuration → integrations → +add

I must still be missing something basic I guess

Thanks for the heads up @ludeeus! This has been merged now.

1 Like