Hi!
I believe my problem is rather common but I have not managed to find any forum or thread that actually solves it.
What I want is simply to display the electricity cost during the last hour. I already have a sensor which is the integral of the electricity cost meaning that if I take the minus the I will then receive the cost for the last hour. But there must be something wrong with my SQL syntax. I have added the following three sensors but only the top one works. The two bottom ones do not show up in the entity list after I have restarted. Any idea on what I am doing wrong in the SQL syntax for the two bottom ones?
- platform: sql
queries:
- name: EMILSTEST1SQL
query: "SELECT * FROM states WHERE entity_id = 'sensor.elkostnad_integral' ORDER BY state_id DESC LIMIT 1;"
column: 'state'
- name: EMILSTEST2SQL
query: "SELECT * FROM states WHERE entity_id = 'sensor.elkostnad_integral' AND created > datetime('now','-1 hour') ORDER BY created ASC LIMIT 1;"
column: 'state'
- name: EMILSTEST3SQL
query: "SELECT * FROM states WHERE entity_id = 'sensor.elkostnad_integral' AND created < datetime('now','-1 hour') ORDER BY created DESC LIMIT 1;"
column: 'state'
Thanks in advance!
/Emil