With the addition of that second storm, lots of things needed fixed so it was a good time to rethink the whole process. Below is the much consolidated new code that supports up to 3 storms. There is not much to change to make it work so here’s the process.
- Completely remove the Hurricane Tracker code.
############################
# Hurricane Tracker
############################
- name: "Hurricane 1"
unique_id: hurricane_1
- Update the Hurricane Storm Coordinates section to look like this:
################################
# Hurricane Storm Coordinates
################################
- name: "Storm 1 Coordinates"
unique_id: storm_1_coordinates
state: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms') %}
{% set winds = (storms[0]['intensity']|int*1.151)|round(2) %}
{% if winds >= 74 and winds <= 95 %}
{% set intensity = 'Cat 1' %}
{% elif winds >= 96 and winds <= 110 %}
{% set intensity = 'Cat 2' %}
{% elif winds >= 111 and winds <= 129 %}
{% set intensity = 'Cat 3' %}
{% elif winds >= 130 and winds <= 156 %}
{% set intensity = 'Cat 4' %}
{% elif winds >= 157 %}
{% set intensity = 'Cat 5' %}
{% else %}
{% set intensity = winds ~ ' MPH' %}
{% endif %}
{{ storms[0]['name'] }}, {{intensity }}
attributes:
latitude: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{storms[0]['latitudeNumeric']}}
longitude: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{storms[0]['longitudeNumeric']}},
distance: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{((distance (storms[0]['latitudeNumeric'], storms[0]['longitudeNumeric'])))|round(2) }} miles
intensity: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{storms[0]['intensity']}}
storm_name: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{ storms[0]['name'] }}
max_winds: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{ (storms[0]['intensity']|int*1.151)|round(2) }} MPH
icon: mdi:hurricane
#
- name: "Storm 2 Coordinates"
unique_id: storm_2_coordinates
state: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms') %}
{% set winds = (storms[1]['intensity']|int*1.151)|round(2) %}
{% if winds >= 74 and winds <= 95 %}
{% set intensity = 'Cat 1' %}
{% elif winds >= 96 and winds <= 110 %}
{% set intensity = 'Cat 2' %}
{% elif winds >= 111 and winds <= 129 %}
{% set intensity = 'Cat 3' %}
{% elif winds >= 130 and winds <= 156 %}
{% set intensity = 'Cat 4' %}
{% elif winds >= 157 %}
{% set intensity = 'Cat 5' %}
{% else %}
{% set intensity = winds ~ ' MPH' %}
{% endif %}
{{ storms[1]['name'] }}, {{intensity }}
attributes:
latitude: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{storms[1]['latitudeNumeric']}}
longitude: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{storms[1]['longitudeNumeric']}},
distance: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{((distance (storms[1]['latitudeNumeric'], storms[1]['longitudeNumeric'])))|round(2) }} miles
intensity: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{storms[1]['intensity']}}
storm_name: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{ storms[1]['name'] }}
max_winds: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{ (storms[1]['intensity']|int*1.151)|round(2) }} MPH
icon: mdi:hurricane
#
- name: "Storm 3 Coordinates"
unique_id: storm_3_coordinates
state: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms') %}
{% set winds = (storms[2]['intensity']|int*1.151)|round(2) %}
{% if winds >= 74 and winds <= 95 %}
{% set intensity = 'Cat 1' %}
{% elif winds >= 96 and winds <= 110 %}
{% set intensity = 'Cat 2' %}
{% elif winds >= 111 and winds <= 129 %}
{% set intensity = 'Cat 3' %}
{% elif winds >= 130 and winds <= 156 %}
{% set intensity = 'Cat 4' %}
{% elif winds >= 157 %}
{% set intensity = 'Cat 5' %}
{% else %}
{% set intensity = winds ~ ' MPH' %}
{% endif %}
{{ storms[2]['name'] }}, {{intensity }}
attributes:
latitude: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{storms[2]['latitudeNumeric']}}
longitude: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{storms[2]['longitudeNumeric']}},
distance: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{((distance (storms[2]['latitudeNumeric'], storms[2]['longitudeNumeric'])))|round(2) }} miles
intensity: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{storms[2]['intensity']}}
storm_name: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{ storms[2]['name'] }}
max_winds: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{{ (storms[2]['intensity']|int*1.151)|round(2) }} MPH
icon: mdi:hurricane
#
On your map change the storm entities to:
- entity: sensor.storm_1_coordinates
label_mode: state
- entity: sensor.storm_2_coordinates
label_mode: state
- entity: sensor.storm_3_coordinates
label_mode: state
It’s optional to add sensor 2 or 3. Your choice.
You can also add a 4th or more sensors by duplicating to above code. Just keep in mind that the JSON is 0 based and the sensors start with storm 1 (so an offset of 1 is needed as seen in the code.)
Optionally, I repurposed the original “Storm Coordinates” to a “Storm Count”.
That code is:
############################
# Hurricane Storm Count
############################
- name: "Storm Count"
unique_id: storm_count
state: >-
{% set storms = state_attr('sensor.current_storms_data','activeStorms')%}
{% for i in range(0, storms | count ) %}
{% endfor %}
{{storms[i] | count + 1 }}
icon: mdi:hurricane
#
This should be the final code, as it addresses all the needs of all previous code plus enabling multiple storm tracking at one time. It also consolidates the code greatly. Please let me know if you have any trouble.