Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95468

Help with value_template in sensor please

$
0
0

@Combie81 wrote:

I have the below code in my sensors.yaml:

  - platform: template
    sensors:
      steven_phone_charging:
        value_template: "{{ state_attr('sensor.sm_g965f_battery_level', 'is_charging') }}"
        friendly_name: Steven Phone Charging
        icon_template: mdi:battery-charging
  - platform: template
    sensors:
      steven_phone_charging_status:
        value_template: >-
          {% set plugged = states('{{ state_attr('sensor.sm_g965f_battery_level', 'is_charging') }}') }
          {% set charge = states('state.sensor.sm_g965f_battery_level) %}

          {% if plugged true and charge 100 %}
            Charged
          {% elif plugged true and charge < 100 %}
            Charging
          {% else %}
            Unplugged
          {% endif %}
        friendly_name: Steven Phone Charging Actual
        icon_template: mdi:battery-charging

The first one returns if the phone is plugged in or not and gives either “true” if plugged in or “false” if not - this works fine.

My issue is with the 2nd sersor where I’m looknig to break this down using the 2nd sensor to check:
if plugged in and battery = 100 then give output of Charged
if plugged in and battery < 100 then give output of Charging
otherwise give output of Unplugged

I’m getting invalid config for the 2nd sensor and looking for help with this as I’m brand new to this templating joy

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 95468

Trending Articles