Sql sensor in configuration.yaml not working

Hi There,

Inside my configuration.yaml I have…

sensor:
    - platform: sql
      name: tester counter
      db_url: !secret maria_URL
      query: SELECT COUNT(*) AS state FROM states WHERE metadata_id = 1198
      column: "state"
      unit_of_measurement: "rows"

I restart HA 2025.4.1 nothing shows up in the developer states section under the name tester
I searched with phpMyAdmin also nothing
There is nothing mentioned in the logs
The maria_URL is used for the recorder and that works.

I tried some variations '," and no quotes helas
I tried to get info from here

can somebody throw me a bone?

Compare your config (in sensors.yaml):

sensor:
    - platform: sql
      name: tester counter...

to the example shown in the documentation you linked to (in configuration.yaml):

sql:
  - name: Sun state
    query: >...

The SQL sensor is not a sensor platform. It is its own integration that goes in configuration.yaml, not sensors.yaml.

1 Like

Indeed Tom was right…

Although I thought it was a sensor and belonged in the sensor it stood on his own.

# Loads default set of integrations. Do not remove.
default_config:

recorder:
  db_url: !secret maria_URL

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes
  extra_module_url:
    - /hacsfiles/lovelace-card-mod/card-mod.js

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
smappee:
  client_id: Guy Forssman
  client_secret: !secret smappee_secret

sql:
  - name: tester_counter
    db_url: !secret maria_URL
    query: >-
      SELECT COUNT(*) AS state FROM states WHERE metadata_id = 1198
    column: "state"
    unit_of_measurement: "rows"



sensor:
  - platform: history_stats
    name: stappende_guy
    entity_id: sensor.pixel_7_guy_steps_sensor
    state: "total"
    type: time
    end: "{{ today_at() }}"
    duration:
      hours: 24
1 Like

If you have a lot of them there’s nothing stopping you using an include to put them in their own file.

1 Like