Yes, you are correct, the binary_sensor is an on/off as opposed to a number.
I see why you have identified that is the possible cause of the issue, i have updated it to reference sensor instead of binary_sensor, but am still getting the same issue…
Question to anyone smarter than me - should the binary_sensor: platform: template part of the code go into the configuration.yaml file or is it ok to be in the yaml file of the esphome component (in this case sonoff sv)?
@Mikkaat, do you know how to use the Developer-Tools of Home Assistant?
Please find both your sensor_fireplace and your binary_fireplace_sensor in the STATES-tab in the Developer-Tools page.
Then look at the Attributes, copy these and show them for both sensors in this topic, please.
Without this information, we will not be able to help you.
To answer you question: both options are possible, it depends on the purpose of the binary_sensor. Best to read the ESPHome documentation and try stuff out.
To see the result always look in Developer Tools - STATES-tab.
The binary_sensor (State is ON or OFF) that you are creating, requires another sensor as the basis (the sensor.furnace in the example). A sensor with a State that shows a value.
The sensor - platform:dallas that is shown in your post above, could work. I depends on what this sensor outputs into its State. Or you could use one of the additional Attributes, when present, as the basis.
So, find this sensor in Developer Tools- States. The name is most likely sensor.fireplace
you created the binary_sensor.furnace_on with the code above, and that is what you should use in the card to display.
the device_class will take care of the icon it shows. Since you’ve created it to be on when sensor.furnace > 2.5, it will use that as the decisive threshold for the binary_sensor to be ‘on’ or ‘off’.
No, the way you did it above is correct. This is the order of things in the yaml:
binary_sensor:
- platform: template
sensors:
name_of_sensor: # this is the slug
friendly_name: # this is the name displayed in the frontend
value_template: >
{{whatever_value is 'True'}}
etc
the use of lambda: and id: is a first for me, please let me ask where did you find the lambda: way of creating templates in Jinja or Ha templating extensions?
Checked both documented ways for creating templates as instructed in HA, but didnt find any reference (yet…)
also, since I can’t enter this in the developer-tools/template,
does this:
|-
if (id(fireplacetemp).state > 30) {
// Fireplace is on
return true;
} else {
// Fireplace is off
return false;
}
I’m using this “exact” example (just for my washing machine) in ESPHome. I doubt that the lambda works in the Home Assistant config, but it sure does in the ESPHome-config.
@cklit - thank you for your help, this resolved the issue. Later tonight, I am going to try the fireplacetemp in the value_template to see what that does, just so i can understand why i cannot achieve the same result with value template.
@bouwew - CMDK has resolved the issue using lamda:, but i am still interested in why value_template would not work. I will completely understand if you do not want to look at this anymore though, so want to say thankyou for all your help and guidance. I am going to revert to my original code later tonight and add the fireplacetemp id as per cmdk’s code, to see if that works, and will reference the sensor.fireplace instead of binary_sensor.fireplace.
Below are the sensors in my Developer Tools, States tab.
Go to Developer Tools - TEMPLATE
Under the blue text Template Editor create a new line and put your template text there. You can see the result on the right side of the page.
Never mind, others already showed how to do it correctly
If it’s a binary sensor that is written for Home Assistant, it goes in configuration.yaml. If it’s written for ESPHome it goes in the ESPHome YAML. Binary Sensors with templates like this go in configuration.yaml.
Apologies for the delayed response. @rlust@KameDomotics
I did get this to work by adding the following code into the ESPyaml
binary_sensor:
- platform: gpio
pin:
number: GPIO5
mode: INPUT_PULLUP
inverted: True
id: fp_state
name: "Fireplace state"
device_class: heat
- platform: template
name: Fireplace sensor
device_class: heat
lambda: |-
if (id(fireplacetemp).state > 30) {
// Fireplace is on
return true;
} else {
// Fireplace is off
return false;
Although i am not using it at the moment (1. its summer here and 2. I have just updated to a power monitor which does not have to wait for the temp to hit target.