From 4b8ea3ed5319d243979d09f0e494abf010457efe Mon Sep 17 00:00:00 2001 From: nordeep Date: Fri, 21 Jan 2022 11:46:23 +0300 Subject: [PATCH] Fix "Previous state of an entity" YAML example (#21268) --- source/_integrations/sql.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/_integrations/sql.markdown b/source/_integrations/sql.markdown index e9902d41c41..6f39fad3a04 100644 --- a/source/_integrations/sql.markdown +++ b/source/_integrations/sql.markdown @@ -108,7 +108,7 @@ Note that the SQL sensor state corresponds to the last row of the SQL result set Based on previous example with temperature, the query to get the former state is : ```sql -SELECT * FROM (SELECT * FROM states WHERE entity_id = 'sensor.temperature_in' ORDER BY state_id DESC LIMIT 2) two_entity ORDER BY state_id ASC LIMIT 1; +SELECT * FROM (SELECT * FROM states WHERE entity_id = 'sensor.temperature_in' ORDER BY state_id DESC LIMIT 2) two_entity ORDER BY state_id ASC LIMIT 1; ``` Thus in yaml ```yaml @@ -117,7 +117,7 @@ sensor: - platform: sql queries: - name: Former_Temperature_In - query: "SELECT * FROM (SELECT state FROM states WHERE entity_id = 'sensor.temperature_in' ORDER BY state_id DESC LIMIT 2) two_entity ORDER BY state_id ASC LIMIT 1;" + query: "SELECT * FROM (SELECT state, state_id FROM states WHERE entity_id = 'sensor.temperature_in' ORDER BY state_id DESC LIMIT 2) two_entity ORDER BY state_id ASC LIMIT 1;" column: "state" ```