Spent two days staring at this trying to figure out why I’m getting ‘unknown’ instead of a numeric value. If I swap the two sensors quoted in the formula for random numeric values I still get ‘unknown’.
Anyone with a clear head care to take a look?! Many thanks!
p.s: the values 30.0 and -15.0 are dummy values for my actual home lat / lon coordinates.
- sensor:
- name: "Distance to GSM Cell"
device_class: distance
unit_of_measurement: "m"
state: >
{{ acos(sin(30.00000)*sin(states('sensor.gsm_serving_cell_lat')|float)+cos(30.00000)*cos(states('sensor.gsm_serving_cell_lat')|float)*cos(states('sensor.gsm_serving_cell_lon')|float)-(-15.00000))*6371 }}
availability: >
{{ not 'unavailable' in
[ states('sensor.gsm_serving_cell_lat'),
states('sensor.gsm_serving_cell_lon'),
] }}
Did you try this formula under development tools ? It is a good way to debug
Try to go step by step in the formula using the development tools (start with the first calculation and than add more calculations) and see where eventually the problem is…
Figured out a bit more info… using the Dev Tools it turns out the formula I grabbed off Google was incorrect. Will try implementing in a different way.