Newbie question creating a switch or sensor i can turn on if another entity > 14

Hi everyone , i am a new hassio user. i have been playing with an idea i have had for weeks now and just cant get it to work the way i want it to.

i am trying to make a sensor or switch that will be turned into the on state when my entity: sensor.starter_battery is above 14 volts, i have tried with automation , and with this config,
.yaml setup , i just cant seem to get it to do what i want.
so i need to create a switch or entity , that i can switch on or off according to the voltage on my starter battery , ie if volts > 14 , then turn on battery is charging switch.

not sure if its the sensor /switch i am making is wrong , or the actual config is not running.
if anyone can please help me . done loads of reading before i headed here, jsut cant seem to get it :|(
here is one of my efforts is config.yaml
i also tried automation to use the service: homeassistant turn on, and switch turn on with no joy

switch:

  • platform: template
    switches:
    engine:
    value_template: {{ is_numeric_state(‘sensor.starter_battery >12’) }}
    turn_on:
    service: homeassistant.turn_on
    entity_id: switch.engine

    turn_off:

    service: homeassistant.turn_off

    entity_id: switch.engine

what you are looking for is a template binary_sensor.

binary_sensor:
  - platform: template
    sensors:
      starter_batt:
        friendly_name: "Battery voltage sensor"
        value_template: >-
          {{ states(sensor.starter_battery)|float > 14 }}
1 Like

thankyou Pippyn.
I will try that now, will that make sensor.starter_bat on or off dependant on the voltage ?

i tried that Pippyn didnt seem to work for me , i now get a new entity in states [binary_sensor.starter_batt] but stays in an off postion even when my voltage is above the 14 as in your example

yes it should create another sensor.
The template i described should have worked. Can you test what the output is in the template editor in the dev tools when you test this:
{{ states(sensor.starter_battery)|float }}

template editor came back with this message
Error rendering template: UndefinedError: ‘sensor’ is undefined

that means that sensor.starter_battery doesn’t exists. I assumed you had a sensor that reported the voltage in HA with the name sensor.starter_battery (as you describe in the first post). Can you check the name of the sensor and replace it in the template?

the syntax is correct, its the same as in states and shows in my states page as a circle with the current voltage in it

image

added pictures

My bad; it should be
{{ states.sensor.starter_battery.state|float }}
can you test that? and if it works adjust the binary sensor.

that gets me back the actual voltage of the sensor battery, yes and it it above 14

however the sensor, i renamed it , still does not turn on

No the name doesn’t matter… the binary_sensor should be:

binary_sensor:
  - platform: template
    sensors:
      starter_batt:
        friendly_name: "Battery voltage sensor"
        value_template: >-
          {{ states.sensor.starter_battery.state|float > 14 }}

Then restart HA. The sensor should be on now

thankyou, will try it now

Thankyou Pippyn wow, i was getting nowhere for weeks.
Bless you

Your welcome. When you’re new to HA it can be difficult some times. But luckily there are many people on this forum who are very willing to help.