I’m trying to send some info from my ESP to a display using json via http post, but I’m having trouble formatting the value before sending.
The value is currently a float with 6 decimal places and needs to be converted to either a float with only one decimal place or a formatted string.
This is what I have so far, but it won’t compile (error: cannot convert ‘float’ to ‘char*’)
Here’s what I have so far (and tempFormat
is set as a std::string
global variable)
interval:
- interval: 30s
then:
- lambda: |-
tempFormat = sprintf ( id(aht20_temp).state, "%.1f");
- interval: 30s
then:
- http_request.post:
url: !secret magicmirror_main
headers:
Content-Type: application/json
json: |-
root["temp"] = tempFormat;
root["sensorId"] = id(sensorID);
verify_ssl: false
I also tried this with no success.
tempFormat = std::to_string( round ( id(aht20_temp).state * 10.0 ) / 10.0);