HASwitchPlate / openHASP-custom-component

Home Assistant custom component for openHASP
https://www.openhasp.com
MIT License
51 stars 12 forks source link

Sunton 8048S board autodiscover does not work. #128

Closed alfem closed 3 months ago

alfem commented 4 months ago

Version of the custom_component

0.7

Configuration


# Sunton 1-8048S070C
plate3:
    objects:
# Temperatura
      - obj: "p0b5"
        properties:
          "text": "{{ states('sensor.time') }}"
      - obj: "p0b6"
        properties:
          "text_color": "{% if -30 <= state_attr('openhasp.plate1','rssi') |int %}green{% elif -31 > state_attr('openhasp.plate1','rssi') |int >= -50 %}orange{% elif -51 > state_attr('openhasp.plate1','rssi') |int >= -80 %}tomato{% else %}red{% endif %}"
      - obj: "p1b1"  # outdoor temperature 
        properties:
          "text": '{{ states("sensor.xiaomi_temp_hum_04_temperature") }}°C'
      - obj: "p1b2"  # indoor 1 temperature 
        properties:
          "text": '{{ states("sensor.xiaomi_temp_hum_01_temperature") }}°C'
      - obj: "p1b3"  # indoor 2 temperature 
        properties:
          "text": '{{ states("sensor.xiaomi_temp_hum_03_temperature") }}°C'
# SWITCHES
      - obj: "p2b1"  # switch toggle button
        properties:
          "val": '{{ 1 if states("switch.sonoff4ch_1") == "on" else 0 }}'
#          "text": '{{ "\uE6E8" if is_state("light.sonoff4ch_1", "on") else "\uE335" | e }}'
        event:
          "up":
            - service: homeassistant.toggle
              entity_id: "switch.sonoff4ch_1"
      - obj: "p2b2"  # switch toggle button
        properties:
          "val": '{{ 1 if states("switch.digoo_nx_sp202_02") == "on" else 0 }}'
#          "text": '{{ "\uE6E8" if is_state("switch.digoo_nx_sp202_02", "on") else "\uE335" | e }}'
        event:
          "up":
            - service: homeassistant.toggle
              entity_id: "switch.digoo_nx_sp202_02"
      - obj: "p2b3"  # switch toggle button
        properties:
          "val": '{{ 1 if states("switch.digoo_nx_sp202_01") == "on" else 0 }}'
#          "text": '{{ "\uE6E8" if is_state("switch.digoo_nx_sp202_01", "on") else "\uE335" | e }}'
        event:
          "up":
            - service: homeassistant.toggle
              entity_id: "switch.digoo_nx_sp202_01"

      - obj: "p2b4"  # switch toggle button
        properties:
          "val": '{{ 1 if states("switch.sonoff_10013aee3f_1") == "on" else 0 }}'
          "text": '{{ "\uE6E8" if is_state("switch.sonoff_10013aee3f_1", "on") else "\uE335" | e }}'
        event:
          "up":
            - service: homeassistant.toggle
              entity_id: "switch.sonoff_10013aee3f_1"

# TV
      - obj: "p3b12" # channel label
        properties:
          "text": "{{ state_attr('media_player.tv_salon','media_title') if state_attr('media_player.tv_salon','media_title') else '-' }}"

      - obj: "p3b15" # sources list
        properties:
          "options": >
            {% if (state_attr('media_player.tv_salon','source_list') != none and states('media_player.tv_salon') not in ['unavailable', 'unknown']) %}
            {{"(no source)\n"|e}}
            {%- for source in state_attr('media_player.tv_salon','source_list') -%}
            {{source+"\n"|e}}{%-if not loop.last%}{%-endif%}{%-endfor%}{%-endif %}
          "val": >
            {% if states('media_player.tv_salon') not in ['unavailable', 'unknown'] %}
            {% if state_attr('media_player.tv_salon','source') == None %}0{% else %}
            {%for source in state_attr('media_player.tv_salon','source_list')%}
            {{loop.index if source == state_attr('media_player.tv_salon','source') }}
            {%-endfor%}{%-endif %}{%-endif %}
          "click": "{{ 'false' if states('media_player.tv_salon') in ['unavailable', 'unknown'] else 'true' }}"
        event:
          "changed":
            - service: media_player.select_source
              data:
                entity_id: "media_player.tv_salon"
                source: "{{ text }}"

      - obj: "p3b18" # play/pause/stop
        properties:
          "text": >
            {% if is_state('media_player.tv_salon', 'playing') %}
            {{ "\uE3E4" | e }}
            {%-else %}
            {{ "\uE40A" | e }}
            {%-endif %}
          "text_opa": "{{ '80' if states('mediaplayer.tv_salon') in ['unavailable', 'unknown'] else '255' }}"
        event:
          "down":
            - service: media_player.media_play_pause
              target:
                entity_id: media_player.tv_salon
          "long":
            - service: media_player.media_stop
              target:
                entity_id: media_player.tv_salon

      - obj: "p3b17" # prev
        properties:
          "text_opa": "{{ '80' if states('media_player.tv_salon') in ['unavailable', 'unknown'] else '255' }}"
        event:
          "down":
            - service: media_player.media_previous_track
              target:
                entity_id: media_player.tv_salon

      - obj: "p3b19" # next
        properties:
          "text_opa": "{{ '80' if states('media_player.tv_salon') in ['unavailable', 'unknown'] else '255' }}"
        event:
          "down":
            - service: media_player.media_next_track
              target:
                entity_id: media_player.tv_salon

      - obj: "p3b20" # volume slider
        properties:
          "val": >
            {% if (state_attr('media_player.tv_salon','volume_level') != none and states('media_player.tv_salon') not in ['unavailable', 'unknown']) %}
            {{ state_attr('media_player.tv_salon','volume_level') * 100 | int(default=80) }}
            {%-endif %}
          "click": "{{ 'false' if states('media_player.tv_salon') in ['unavailable', 'unknown'] else 'true' }}"
        event:
          "changed":
            - service: media_player.volume_set
              data:
                entity_id: media_player.tv_salon
                volume_level: "{{ val | int / 100 }}"
          "up":
            - service: media_player.volume_set
              data:
                entity_id: media_player.tv_salon
                volume_level: "{{ val | int / 100 }}"

      - obj: "p3b21" # power
        properties:
          "text_color": "{{ '#B00000' if states('media_player.tv_salon') == 'off' else '#FFFFFF' }}"
          "text_opa": "{{ '80' if states('media_player.tv_salon') in ['unavailable', 'unknown'] else '255' }}"
        event:
          "down":
            - service: media_player.toggle
              data:
                entity_id: media_player.tv_salon

      - obj: "p3b24" # mute
        properties:
          "text": >
            {% if state_attr('media_player.tv_salon', 'is_volume_muted') %}
            {{ "\uE75F" | e }}
            {%-else %}
            {{ "\uE57E" | e }}
            {%-endif %}
          "text_opa": "{{ '80' if states('media_player.tv_salon') in ['unavailable', 'unknown'] else '255' }}"
        event:
          "down":
            - service: media_player.volume_mute
              data:
                entity_id: tv_salon
                is_volume_muted:  >
                  {% if state_attr('media_player.tv_salon', 'is_volume_muted') %}
                  false
                  {% else %}
                  true
                  {%-endif %}                
# MPD
      - obj: "p4b12" # artist label
        properties:
          "text": "{{ state_attr('media_player.mpd','media_artist') if state_attr('media_player.mpd','media_artist') else '-' }}"

      - obj: "p4b13" # title label
        properties:
          "text": "{{ state_attr('media_player.mpd','media_title') if state_attr('media_player.mpd','media_title') else '-' }}"

      - obj: "p4b15" # sources list
        properties:
          "options": >
            {% if (state_attr('media_player.mpd','source_list') != none and states('media_player.mpd') not in ['unavailable', 'unknown']) %}
            {{"(no source)\n"|e}}
            {%- for source in state_attr('media_player.mpd','source_list') -%}
            {{source+"\n"|e}}{%-if not loop.last%}{%-endif%}{%-endfor%}{%-endif %}
          "val": >
            {% if states('media_player.mpd') not in ['unavailable', 'unknown'] %}
            {% if state_attr('media_player.mpd','source') == None %}0{% else %}
            {%for source in state_attr('media_player.mpd','source_list')%}
            {{loop.index if source == state_attr('media_player.mpd','source') }}
            {%-endfor%}{%-endif %}{%-endif %}
          "click": "{{ 'false' if states('media_player.mpd') in ['unavailable', 'unknown'] else 'true' }}"
        event:
          "changed":
            - service: media_player.select_source
              data:
                entity_id: "media_player.mpd"
                source: "{{ text }}"

      - obj: "p4b14" # progressbar
        properties:
          "max": "{{ state_attr('media_player.mpd','media_duration') or 0 | int }}"
          "val": "{{ state_attr('media_player.mpd','media_position') or 0| int }}"

      - obj: "p4b18" # play/pause/stop
        properties:
          "text": >
            {% if is_state('media_player.mpd', 'playing') %}
            {{ "\uE3E4" | e }}
            {%-else %}
            {{ "\uE40A" | e }}
            {%-endif %}
          "text_opa": "{{ '80' if states('mediaplayer.mpd') in ['unavailable', 'unknown'] else '255' }}"
        event:
          "down":
            - service: media_player.media_play_pause
              target:
                entity_id: media_player.mpd
          "long":
            - service: media_player.media_stop
              target:
                entity_id: media_player.mpd

      - obj: "p4b17" # prev
        properties:
          "text_opa": "{{ '80' if states('media_player.mpd') in ['unavailable', 'unknown'] else '255' }}"
        event:
          "down":
            - service: media_player.media_previous_track
              target:
                entity_id: media_player.mpd

      - obj: "p4b19" # next
        properties:
          "text_opa": "{{ '80' if states('media_player.mpd') in ['unavailable', 'unknown'] else '255' }}"
        event:
          "down":
            - service: media_player.media_next_track
              target:
                entity_id: media_player.mpd

      - obj: "p4b20" # volume slider
        properties:
          "val": >
            {% if (state_attr('media_player.mpd','volume_level') != none and states('media_player.mpd') not in ['unavailable', 'unknown']) %}
            {{ state_attr('media_player.mpd','volume_level') * 100 | int(default=80) }}
            {%-endif %}
          "click": "{{ 'false' if states('media_player.mpd') in ['unavailable', 'unknown'] else 'true' }}"
        event:
          "changed":
            - service: media_player.volume_set
              data:
                entity_id: media_player.mpd
                volume_level: "{{ val | int / 100 }}"
          "up":
            - service: media_player.volume_set
              data:
                entity_id: media_player.mpd
                volume_level: "{{ val | int / 100 }}"

      - obj: "p4b21" # power
        properties:
          "text_color": "{{ '#B00000' if states('media_player.mpd') == 'off' else '#FFFFFF' }}"
          "text_opa": "{{ '80' if states('media_player.mpd') in ['unavailable', 'unknown'] else '255' }}"
        event:
          "down":
            - service: media_player.toggle
              data:
                entity_id: media_player.mpd

      - obj: "p4b22" # repeat
        properties:
          "text": >
            {% if is_state_attr('media_player.mpd', 'repeat', 'one') %}
            {{ "\uE458" | e }}
            {% elif is_state_attr('media_player.mpd', 'repeat', 'all') %}
            {{ "\uE456" | e }}
            {%-else %}
            {{ "\uE457" | e }}
            {%-endif %}
          "text_opa": "{{ '80' if states('media_player.mpd') in ['unavailable', 'unknown'] else '255' }}"
        event:
          "down":
            - service: media_player.repeat_set
              data:
                entity_id: mpd
                repeat: >
                  {% if is_state_attr('media_player.mpd', 'repeat', 'one') %}
                  all
                  {% elif is_state_attr('media_player.mpd', 'repeat', 'all') %}
                  off
                  {% elif is_state_attr('media_player.mpd', 'repeat', 'off') %}
                  one
                  {%-endif %}

      - obj: "p4b23" # shuffle
        properties:
          "text": >
            {% if state_attr('media_player.mpd', 'shuffle') %}
            {{ "\uE49D" | e }}
            {%-else %}
            {{ "\uE49E" | e }}
            {%-endif %}
          "text_opa": "{{ '80' if states('media_player.mpd') in ['unavailable', 'unknown'] else '255' }}"
        event:
          "down":
            - service: media_player.shuffle_set
              data:
                entity_id: mpd
                shuffle:  >
                  {% if state_attr('media_player.mpd', 'shuffle') %}
                  false
                  {% else %}
                  true
                  {%-endif %}

      - obj: "p4b24" # mute
        properties:
          "text": >
            {% if state_attr('media_player.mpd', 'is_volume_muted') %}
            {{ "\uE75F" | e }}
            {%-else %}
            {{ "\uE57E" | e }}
            {%-endif %}
          "text_opa": "{{ '80' if states('media_player.mpd') in ['unavailable', 'unknown'] else '255' }}"
        event:
          "down":
            - service: media_player.volume_mute
              data:
                entity_id: mpd
                is_volume_muted:  >
                  {% if state_attr('media_player.mpd', 'is_volume_muted') %}
                  false
                  {% else %}
                  true
                  {%-endif %}                
# INFO
      - obj: "p5b5" # rssi
        properties:
          "text": "rssi: {{ state_attr('openhasp.plate3','rssi') }}"

Describe the bug

I flashed and connected a new Sunton 8048S board, but Home Assistant integration does not show it up. I restarted HASS and the board a few times, but that did not solve the issue.

Debug log

024-05-28 15:14:45.747 DEBUG (MainThread) [custom_components.openhasp.config_flow] Discovered ZeroConf: {'dim': '[]', 'light': '[]', 'power': '[]', 'input': '{}', 'uri': 'http://192.168.1.123', 'node_t': 'hasp/plate3/', 'sw': '0.7.0-rc12', 'pages': '12', 'hwid': 'f0f5bd4a0568', 'mf': 'openHASP', 'mdl': 'Sunton 1-8048S070C', 'node': 'plate3'}
2024-05-28 15:14:45.748 DEBUG (MainThread) [custom_components.openhasp.config_flow] [hasp/plate3] Discovered pages = 12
2024-05-28 15:14:45.748 DEBUG (MainThread) [custom_components.openhasp.config_flow] [hasp/plate3] Discovered power = []
2024-05-28 15:14:45.748 DEBUG (MainThread) [custom_components.openhasp.config_flow] [hasp/plate3] Discovered light = []
2024-05-28 15:14:45.748 DEBUG (MainThread) [custom_components.openhasp.config_flow] [hasp/plate3] Discovered dim = []
2024-05-28 15:14:45.748 DEBUG (MainThread) [custom_components.openhasp.config_flow] [hasp/plate3] Discovered input = {}
alfem commented 4 months ago

I folllowed @bh213 suggestion in openHASP repository and commented out this line

self._abort_if_unique_id_configured()

in config_flow.py.

After a restart, the Sunton board showed up (twice) in openhasp integration. I tried to configure them: the first one was in a weird state, but the second one worked a treat.

alfem commented 4 months ago

I can barely remember I was messing with my new board plate name, perhaps it left some id stored in hass database.

fvanroie commented 3 months ago

I guess this can be closed now?

alfem commented 3 months ago

Yes, let it in the twilight zone :-D