Oil Tank Level Sensor

Finding the real problem, my sensor won’t read past 1.1 meeter. any advice? it is a JSN-SR04T

@DeanoX - Hi, any chance you could tell me what card you are using in your screenshot in the first post? Appreciate this is an old thread, but I’m implementing a very similar sensor and am trying to achieve a similar display in my dashboard, but struggling. It looks like an entities card, but I can’t for the life of me manage to display my images (like your green tick) in my entities card, based on the current sensor state.

@DeanoX It’s a Glance card

Thanks, I tried using the Glance card, however I can’t get the state based Icon to display, let alone the state based picture. There is empty space when I set the Glance card up to ‘show icon’, so this looks like it could be down to my template sensor state icon config.

image

This is using the default Glance card config:

show_name: true
show_icon: true
show_state: true
type: glance
entities:
  - entity: sensor.oil_status
state_color: false

I would settle for the icon in a Glance card changing based on the template sensor state, but the OP seems to have a picture showing in his Glance card based on the state

@Scoff

Have you set the options needed for the HA Template Sensor template? Also you need to upload the images to the config/www/ folder as well.

Thanks, yes I’ve created the following Template Sensor in HA, but feel this could be where the issue lies (still very inexperienced with templating and HA in general!):

template:
  - sensor:      
      - name: "Oil Status"
        state: >
          {% if states.sensor.oil_level.state == 999 %}
          ERROR
          {% elif states.sensor.oil_level.state | int > 75 %}
          GOOD
          {% elif states.sensor.oil_level.state | int > 50 %}
          OK
          {% elif states.sensor.oil_level.state | int > 25 %}
          LOW
          {% else %} 
          WARNING
          {% endif %}
        icon: >
          {% if is_state('sensor.oil_status', 'ERROR') %}
          mdi:alert-decagram
          {% elif is_state('sensor.oil_status', 'GOOD') %}
          mdi:check-circle
          {% elif is_state('sensor.oil_status', 'OK') %}
          mdi:check-circle-outline
          {% elif is_state('sensor.oil_status', 'LOW') %}
          mdi:alert-circle-outline
          {% else %} 
          mdi:alert-circle
          {% endif %}
        picture: >
          {% if is_state('sensor.oil_status', 'ERROR') %}
          /local/cancel.png
          {% elif is_state('sensor.oil_status', 'GOOD') %}
          /local/green.png
          {% elif is_state('sensor.oil_status', 'OK') %}
          /local/yellow.png
          {% elif is_state('sensor.oil_status', 'LOW') %}
          /local/amber.png
          {% else %} 
          /local/red.png
          {% endif %}

I have the images saved in the config/www/ folder as well. Even if my Template Sensor code is incorrect, then I would have thought the mdi: icons would show in either the Entity card, or Glance card, according to the state of the sensor, but there is just blank space where the icon should be.

After some trial and error I managed to get the pictures to display. The problem seemed to be having both icons and pictures defined for my template sensor. After removing the icon code block, my pictures started displaying. I can leave my code like this as I’d rather having the pictures than the icons anyway. Just in case anyone else comes across this with a similar issue.

Bonjour peux tu partager ton. Code yaml sous esphome car qua’d je rentre le programme yaml sensor ultrasonic je n’ai aucune donnes en retour merci pour ta réponse

esphome:
  name: esp_oilsensor
  platform: ESP32
  board: nodemcu-32s

wifi:
  domain: .local
  networks:
  - ssid: 
    password: 
  - ssid: 
    password: 
  manual_ip:
    static_ip: 192.168.1.200
    gateway: 192.168.1.1
    subnet: 255.255.255.0

# Enable logging
logger:
# Enable Home Assistant API
api:

ota:

substitutions:
# Unique ID
  esp_id: "esp_oil"

#dallas:
#  - pin: D1

binary_sensor:
  - platform: status
    name: "Oil Sensor Status"

sensor:
  - platform: ultrasonic
    trigger_pin: GPIO4
    echo_pin: GPIO5
    name: "Oil Tank SR04"
    unit_of_measurement: "cm"
    id: ${esp_id}_sr04
    update_interval: 5s
    accuracy_decimals: 1
    filters:
      - multiply: 100
      - sliding_window_moving_average:
          window_size: 12
          send_every: 12

  - platform: template
    name: "Oil Tank Level"
    id: ${esp_id}_level
    accuracy_decimals: 0
    unit_of_measurement: "%"
    icon: "mdi:oil"
    lambda: |-
      if (id(${esp_id}_sr04).state > 160 ) {
        return 999;
      } else if (id(${esp_id}_sr04).state > 125) {
        return 0;
      } else {
        return (125 - (int) id(${esp_id}_sr04).state);
      }
    update_interval: 30s
 
1 Like

Hey, started this project for oil measurement: