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

Current year variable in SQL sensor query?

$
0
0

Hi,

I have the following SQL sensor that gets the last value of a specific month given in the (My)SQL query. Now the LAST_DAY has a “hardcoded” year, is it possible to fill in the current year using a variable or such? Thanks!

  - platform: sql
    db_url: !secret db_mysql
    queries:
      - name: sql_kwh_maandelijks_december
        query: "SELECT * FROM states WHERE entity_id = 'sensor.energy_import_total_maandelijks_kwh' AND state != 'unknown' AND DATE(created) = LAST_DAY('2020-12-1') ORDER BY state DESC LIMIT 1;"
        column: 'state'
        unit_of_measurement: kWh

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 106276

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>