today I installed Home Assistant (version 0.96.5). With a NodeMCU microcontroller I added the TSL2165 lux sensor to Home Assistant and the sensor appear to deliver values correctly. So far so good.
Is it somehow possible to display the sensor data as strings instead of numerical values? For example, for a lux range from 0 to 50 display the value “dark” and for a lux range higher than 50 display the value “light”.
Well this is the exact resource I based my previous post on.
I used the “renaming sensor output” example and tried to apply it to my case. What did I do wrong?
Well, your platform says “tsl2561” when the platform should be “template” as shown on that page, for starters.
A template sensor is a entirely new sensor. It doesn’t replace your existing sensor. It uses your existing sensor to create a new sensor that works the way you want it to.
Like this:
sensor:
- platform: template
sensors:
my_new_sensor:
friendly_name: "My New Sensor"
value_template: >-
{% if states('sensor.lux') | float > 50 %)
light
{% else %}
dark
{% endif %}
However, if you really only want two states (light and dark) and you’re not set on having the strings be there, you just want a way to know if a sensor is over a certain amount, then a binary_sensor template is better.
Thanks for the in-depth answer. I will try it out later. You are absolutely right, i didnt use the platform “template”.
This helped me understand a lot in particular: “A template sensor is a entirely new sensor. It doesn’t replace your existing sensor. It uses your existing sensor to create a new sensor that works the way you want it to.”
As of right now I have only worked with ESPHome and it created the following .yaml:
/config/esphome/node_multisensor.yaml
I just downloaded the Configurator to have a look at my configuration.yaml. I do not see the “node_multisensor.yaml” in it. Could that be the problem? Do I have to create these templates in the configuration.yaml? If so, why do these other sensors work while not being in the configuration.yaml either?
I do have heard before that its smart to split up the .yaml files. But to be honest, right now I just need a proof of concept for myself. Making it more enjoyable to edit in the future is definately on the list.
ESPHome YAML is for the specific device. It doesn’t go in configuration.yaml. ESPHome uses it to configure the device itself.
The ESPHome device then connects to Home Assistant in a way that adds entities without needing any information in configuration.yaml.
You don’t need to split your configuration up. Especially if you’re just starting out. I only pointed out that mine was split to suggest why, if there is a bug in Home Assistant, you are seeing it and I am not.
Check your tabs vs spaces, as that can throw things off, but I don’t think it is in this case. Make sure that all of your indentation either uses tabs or spaces, but not both (spaces is generally considered better).
If that doesn’t solve anything, I would remove everything you pasted above from configuration.yaml EXCEPT for the binary_sensor.template. Then see if you get the same error. Then slowly add the pieces back in, one-by-one, until the error comes back.
Thank you very much for taking the time to help a beginner. Really appreciate it, even though my problem this isnt solved.
I will let you (and everyone who might read this) know what was the error if i can find it. Weird thing is that even when I delete everything else from the .yaml and copy/paste the example code, the error still persists…
Yeah, everything works. As soon as i paste the example code, the error occurs.
I will try later to put the example code in the configuration.yaml. Someone on reddit mentioned that templating might not be supported by esphome.
If that doesnt work, im out of ideas.
templating is NOT supported by ESPHome. And if that’s where you’re putting the binary_sensor.template code that’s exactly the problem.
If you want the ESPHome device to actually create this binary sensor, instead of having it created in Home Assistant, you’ll probably need to use a lambda in ESPHome, though, I’m not fluent enough in it to help with the configuration.
I guess pasting the code into the configuration.yaml doesnt do the trick, does it?
At least i can confirm that the code is being accepted in the configuration.yaml file. The new sensor however does not appear.
It should be all you need, really. Just paste it in there, in addition to having your ESPHome device working. Check HomeAssistant’s error log to make sure nothing went wrong with the binary_sensor, and it should show up in dev-states.