Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input_text limited to 255 Characters so won't Hold Five alert IDs #56

Open
kaijk opened this issue Apr 9, 2022 · 5 comments
Open

input_text limited to 255 Characters so won't Hold Five alert IDs #56

kaijk opened this issue Apr 9, 2022 · 5 comments

Comments

@kaijk
Copy link

kaijk commented Apr 9, 2022

Version, Current, V1.3?
(Note, I renamed entities to the 'motherlode' zone from 'weatheralerts'

** Bug **
Alert IDs are stored in an input_text helper. These are limited to 255 characters total, but the total concatenated string for five alerts is 349 Characters. For example:

urn:oid:2.49.0.1.840.0.f9a6097f6d0e41b9224fd529f005effa05ff9757.001.1 
urn:oid:2.49.0.1.840.0.c6397b712c111522feb786d9bab7d545aa86668d.001.1 
urn:oid:2.49.0.1.840.0.9e404887452349de9b387fa6efa8d1a6ada8541a.002.1 
urn:oid:2.49.0.1.840.0.7f73c6a9ede216c8f21fd80675b4ad8cfd435f81.001.1 
urn:oid:2.49.0.1.840.0.0ad126d6a7c5c2d956b8e75693617d4dbb0cf112.001.1

Log

Logger: homeassistant.components.input_text
Source: components/input_text/__init__.py:274
Integration: Input text ([documentation](https://www.home-assistant.io/integrations/input_text), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+input_text%22))
First occurred: 1:29:37 PM (2 occurrences)
Last logged: 1:29:47 PM
Invalid value: urn:oid:2.49.0.1.840.0.f9a6097f6d0e41b9224fd529f005effa05ff9757.001.1 urn:oid:2.49.0.1.840.0.c6397b712c111522feb786d9bab7d545aa86668d.001.1 urn:oid:2.49.0.1.840.0.9e404887452349de9b387fa6efa8d1a6ada8541a.002.1 urn:oid:2.49.0.1.840.0.7f73c6a9ede216c8f21fd80675b4ad8cfd435f81.001.1 urn:oid:2.49.0.1.840.0.0ad126d6a7c5c2d956b8e75693617d4dbb0cf112.001.1 (length range 0 - 255)

Input_text definition:

input_text:
  motherlode_triggered_ui_alert_ids:
    name: Motherlode Triggered Weather Alert IDs - UI
    icon: mdi:information-variant
    max: 255
    initial: None

Input_text action from automation:

      - service: input_text.set_value
        data: #data_template:
          entity_id: input_text.motherlode_triggered_ui_alert_ids
          value: "{{ state_attr('sensor.motherlode_alert_1', 'alert_id') }} {{ state_attr('sensor.motherlode_alert_2', 'alert_id') }} {{ state_attr('sensor.motherlode_alert_3', 'alert_id') }} {{ state_attr('sensor.motherlode_alert_4', 'alert_id') }} {{ state_attr('sensor.motherlode_alert_5', 'alert_id') }}"
@kaijk kaijk changed the title input_text limited to 255 Characters input_text limited to 255 Characters so won't Hold Five alert IDs Apr 9, 2022
@jlverhagen
Copy link
Collaborator

Thanks for the report. The NWS changed the alert ID format at some point and made them much longer. I think I can fix it by adding a second input_text helper and splitting the alert IDs between two input_text helpers. It should only take some minor adjustments to the UI Notification automation.

@kaijk
Copy link
Author

kaijk commented Apr 19, 2022

Thanks for your attention to this. We happen to have some residual/reappearing winter that is generating a flurry ;) of NWS alerts that make for good testing.

Might you use an attribute to store these data? Attributes are not bound by the 255 character limit for an entity's state .

@mjnovotny82
Copy link

We could pipe in a replace() to remove urn:oid:2.49.0.1.840.0. from the alert IDs in your weatheralerts.yaml file. You would want to add | replace('urn:oid:2.49.0.1.840.0.','') to each of the five [0-4] alert_id sections . This should drop it down to around 234 characters.

Before

      alert_id: >-
        {% if not is_state('sensor.weatheralerts_1', '0') and not is_state('sensor.weatheralerts_1', 'unavailable') and not is_state('sensor.weatheralerts_1', 'unknown') and is_state('sensor.weatheralerts_1_alert_1', 'on') or (is_number(states('sensor.weatheralerts_1')) and (states('sensor.weatheralerts_1')|int > 0)) %}
          {{ states.sensor.weatheralerts_1.attributes.alerts[0].id }}
        {% else %}
          None
        {% endif %}
    # skip some lines #
      alert_id: >-
        {% if not is_state('sensor.weatheralerts_1', 'unavailable') and not is_state('sensor.weatheralerts_1', 'unknown') and is_state('sensor.weatheralerts_1_alert_2', 'on') or (is_number(states('sensor.weatheralerts_1')) and (states('sensor.weatheralerts_1')|int > 1)) %}
          {{ states.sensor.weatheralerts_1.attributes.alerts[1].id }}
        {% else %}
          None
        {% endif %}

After

      alert_id: >-
        {% if not is_state('sensor.weatheralerts_1', '0') and not is_state('sensor.weatheralerts_1', 'unavailable') and not is_state('sensor.weatheralerts_1', 'unknown') and is_state('sensor.weatheralerts_1_alert_1', 'on') or (is_number(states('sensor.weatheralerts_1')) and (states('sensor.weatheralerts_1')|int > 0)) %}
          {{ states.sensor.weatheralerts_1.attributes.alerts[0].id | replace('urn:oid:2.49.0.1.840.0.','') }}
        {% else %}
          None
        {% endif %}
    # skip some lines #
      alert_id: >-
        {% if not is_state('sensor.weatheralerts_1', 'unavailable') and not is_state('sensor.weatheralerts_1', 'unknown') and is_state('sensor.weatheralerts_1_alert_2', 'on') or (is_number(states('sensor.weatheralerts_1')) and (states('sensor.weatheralerts_1')|int > 1)) %}
          {{ states.sensor.weatheralerts_1.attributes.alerts[1].id | replace('urn:oid:2.49.0.1.840.0.','') }}
        {% else %}
          None
        {% endif %}
    # rinse and repeat for [2], [3], [4] #

I have not see urn:oid:2.49.0.1.840.0. changed in year plus of using weatheralerts.

@kaijk
Copy link
Author

kaijk commented Nov 5, 2022

I'm trying your suggestion @mjnovotny82. We should be having a full compliment of alerts over the next few days.

I'd also considered using an attribute for the data instead of a state, but haven't pursued it.

@regularguy01
Copy link

I fixed this by adding

.split('urn:oid:2.49.0.1.840.0.')[1],

on line 193 of sensor.py

the full line looks like
"id": properties.get("id", "null").split('urn:oid:2.49.0.1.840.0.')[1],

The URN (universal registered number) never changes for NWS and is specific to the USA.

Then you don't need yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants