Convert sensor data from C to F

I have some Wireless Sensor Tags. They report temperature and humidity. Currently I get their data into home assistant via http://homeassistant:8123/api/states/sensor.(sensorname).

Currently they only report temperature in Celcius. As such, my JSON posted to the URL looks like

{“state”:“32”, “attribute”:{“friendly_name”:“Temp sensor XXX”,“humidity”:“43”,“unit_of_measurement”:“C”}}

This works fine…except I use fahrenheit.

I was wondering if there was a way to define a “sensor filter” to where if it sees a unit_of_measurement as “C” to then globally convert the data to “F”? Not sure if i should write a sensor to this?

The wireless tags have a limit on the length of the URL + json, so I’d really prefer to do any modifications on home assistant. I’d also love to figure out how to graph the temperature AND humidity on the same “state”…if possible

The only way I know to do the conversion is to wrap a sensor with a 2nd template_sensor.

So, if your tag reports to sensor.sensor1

You would make a template_sensor that looks something like this

  - platform: template
      - sensor.sensor1
      unit_of_measurement: '°F'
      value_template: >
        {{((states('sensor.sensor1')* 9 / 5)+ 32)|round(1)}}

You would probably have to make a custom component if you want to graph both values on the same sensor.

1 Like

This would work…except I’m having the check_config script throw an error. I’ll have to look into the template further to figure out how to format this correctly. Thank you.

My config throws an error with the degree symbol despite me seeing it in other examples. It could be that.

Granted, I didn’t actually check the formatting. There is a template page under the dev options in the front end that you can use to confirm the template syntax and results.

I realized that in my example the states returns a non-float value. So it has to look more like

{{ ((float(states('sensor.sensor1')) * 9 / 5 )  +  32) | round(1) }}

I just bought a couple of these wireless tags. Any chance you could elaborate on how you are getting data into HA? I know enough to know I don’t know anything but still want to play around. Any help to get me started would be appreciated.

URL calling and http sensor.

Your URL for when a tag sends and update would be something like


Replacing h.a with your IP address

And the data would be something like

{“state”: “<%{2}*9/5+32%>”, “attributes”: {“humidity”:"{3}",“unit_of_measurement”:“°F”}}

Not the most ideal way but it works.

So do I create an KumoApp for that? I afraid I’m missing even the basics here. With the Philips I setup a REST sensor with a resource pointing to my philips hue hub. What you’re suggesting is I push data from the Wireless Tag Manager? Again through what can you give me an example?

Thanks and sorry for being so obtuse.

No kumo apps. In the web or phone app, under each sensor, there’s a right arrow. Click that for more options. Click URL calling. Check the first box, it will let you enter a URL. Click the right arrow again, select post and copy that data I have. Click anywhere else to close. Check the box “this URL uses private IP address”. Next update you should have a sensor in ha.

Hmm. Don’t see that option on the iPhone App. I can get into each sensor and see the options to control it but no URL calling. I’ll check the web app when I get home. Thanks for the info. :slight_smile:

Great I see it in the web app. I have a password for HA do I need to include that in the URL? I am assuming so. Is there any reference for URL calls to HA that might help with this? I’ve done what you’ve suggested but I’m not getting any sensors showing up.

1 Like

Got it in as a REST sensor. Once I got the OAuth code I used this config:

- platform: rest
    name: 'Wireless 1 Temp'
    method: POST
    value_template: '{{ value_json.d[0].temperature | round(2) }}'
    unit_of_measurement: °C
      Content-Type: application/json
      Authorization: 'Bearer xxxxOAuthCodexxx'

I’ll try a binary sensor tonight. This seems pretty reasonable. I can get all data and tags this way. Seems to try to post info about my WeMo switches which as far as I know I did not link. Although in iOS Wireless app something flashes on about WeMo when I start it up.

Very interesting.

As far as the password in the URL - the sensors don’t support it. You would have to have the IP of the tag manager listed under trusted_networks so that it bypasses authentication. Also make sure the check box is checked for “private IP address”. This will have the tag manager call the URL vs the website. POST is required.

Is there an advantage to your method vs mine? I guess yours is local? For temp, humidity, lux the API should be good. Binary sensor may be too slow.

I’ll give your method another try. That’s the piece I was missing I’ll bet. Is trusted_network an HA thing? Must be right?

I am pretty against having to call something on the internet to get information on a device which lives on my local network. The developers of the wireless tags don’t give any real option otherwise so it’s what works for me.

Everything is pretty instantaneous. As soon as I see the light flash on my PIR motion detector HA is turning my lights on. For things like my temperature updates they don’t immediately show - only when the actual tag contacts the manager to send an update…but I rather that. I don’t see a point in querying a website every 2 minutes when my tags only update every 10 minutes.

Yes, trusted_networks is a HA thing:

   api_password: yourpassword

Another handy trick I use is to set my phone to a DHCP reservation (in the router) so that it always receives say Using that config your phone will not prompt for a password when on your wifi.

Another roadblock. I have things setup with SSL. URL calling doesn’t support https. Hmm.

Does ha now have SSL built in? I thought people were putting nginx in front?

yes,ssl support

Yes. I’ve had in place with letsencrypt since I started with HA. Thought it good practice if exposed over internet.

Might look at Tor instead.

Why not leave it running HTTP and just put a nginx proxy in front for internet facing purposes? I only use a VPN for remote access, so I hadn’t bothered setting up SSL