I have a remote database on my network that I’m querying from HA. HA makes the query and remote database returns value. I have this bit working
sensor:
- platform: sql
db_url: mysql://user:[email protected]/rpidb
queries:
- name: Bedroom
query: "SELECT 'device', 'status' FROM 'device_table' WHERE 'device' LIKE 'br';"
column: "status"
This creates the sensor.bedroom entity with ‘device’ and ‘status’ attributes.
The problem is the status value is a string and it needs to be a float. The SQL page talks using value_template and links to Templating. The Templating page talks about converting values to int and float so numeric comparisons work right, the exact problem I’m having.
I would like to add some attributes but I can’t figure it out. It would be nice to use float for triggers, and int and round for the dashboard. I wish this would work!
sensor.bedroom.float = float( sensor.bedroom.status )
sensor.bedroom.int = int( sensor.bedroom.status )
sensor.bedroom.round = round( sensor.bedroom.status, 1 )
Nothing I try in DevTools>Template works out in configuration.yaml. I need help with this. Or maybe my approach needs help. I don’t know!
I’m an HA beginner. If I couldn’t read and write my remote database, I’m wasn’t going to be interested in HA for too long. After struggling for a few days, the first database query finally worked, and I knew I was over the hump.
My remote database is on a RPi3 and controls my HVAC and does a few other things. It’s been doing a great job for years. Getting HA to work the way I think it can will really be a big addition to what I have now. Thx!