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

[bug] hass entity names are now being prefixed with - #162

Closed
1 of 3 tasks
chilicheech opened this issue Jan 6, 2021 · 6 comments · Fixed by #218
Closed
1 of 3 tasks

[bug] hass entity names are now being prefixed with - #162

chilicheech opened this issue Jan 6, 2021 · 6 comments · Fixed by #218
Assignees
Labels
bug Something isn't working

Comments

@chilicheech
Copy link
Contributor

chilicheech commented Jan 6, 2021

Version

Build/Run method

  • Docker
  • PKG
  • Manually built (git clone - npm install - npm run build )

zwavejs2mqtt version: 1.0.0.alpha.2

Describe the bug
Before this version HASS entity names were being reported correctly, for instance, patio_lights_dimmer. In this version the name is being prefixed with a dash, -patio_lights_dimmer. This is probably due to the introduction of the entity name template feature, that has a default template of %loc-%n_%o. However, this "breaks" the name when there's no location present. When the location is empty/null, the dash should be removed.

Expected behavior
Using the default entity name template, when the node's location is NOT empty/null, the effective template should be what it is now: %loc-%n_%o. However, when node's location IS empty/null, the effective template should be %n_%o (without a dash for a prefix).

Additional context
Here's a picture of my config:
Screen Shot 2021-01-06 at 11 49 31 AM
Here's a picture of the config of the patio_lights device:
Screen Shot 2021-01-06 at 11 59 05 AM

And here's the generated HASS discovery:

{
  "type": "light",
  "object_id": "dimmer",
  "discovery_payload": {
    "schema": "template",
    "brightness_template": "{{ (value_json.value / 99 * 255) | round(0) }}",
    "state_topic": "z2m/2/38/0/currentValue",
    "state_template": "{{ \"off\" if value_json.value == 0 else \"on\" }}",
    "command_topic": "z2m/2/38/0/targetValue/set",
    "command_on_template": "{{ ((brightness / 255 * 99) | round(0)) if brightness is defined else 255 }}",
    "command_off_template": "0",
    "device": {
      "identifiers": [
        "zwavejs2mqtt_0xc5b5c9e5_node2"
      ],
      "manufacturer": "Zooz",
      "model": "Dimmer Paddle Switch (ZEN22)",
      "name": "patio_lights",
      "sw_version": "3.5"
    },
    "name": "-patio_lights_dimmer",
    "unique_id": "zwavejs2mqtt_0xc5b5c9e5_2-38-0-currentValue"
  },
  "discoveryTopic": "light/patio_lights/dimmer/config",
  "values": [
    "38-0-currentValue",
    "38-0-targetValue"
  ],
  "persistent": false,
  "ignoreDiscovery": false,
  "id": "light_dimmer"
}

Notice how it now sets "name": "-patio_lights_dimmer" whereas before the entity name template feature was introduced it would correctly set it to "name": "patio_lights_dimmer".

@chilicheech chilicheech added the bug Something isn't working label Jan 6, 2021
@robertsLando
Copy link
Member

@chilicheech Essentially the problem is that location is missing, did you tried to remove %loc from the entity name plaeholder?

@varet80
Copy link
Collaborator

varet80 commented Jan 7, 2021

IT would be a good idea to check the name and remove the - when is first letter, but some people might need to keep it.
another way is to ahve a "default" room/location set when no location exists

@chilicheech does all your entities not use location?

@chilicheech
Copy link
Contributor Author

@billiaz that is correct. All my entities don't use location, a.k.a. the location is empty/null. I could adjust the template, but I believe the default template should produce a name that doesn't start with a dash when the location is empty, which was the behavior before we added the template feature.

@varet80
Copy link
Collaborator

varet80 commented Jan 11, 2021

@chilicheech if you are able to compile from a branch can you compile from https://github.com/zwave-js/zwavejs2mqtt/tree/cleanup_hyphen
If this works, I will create a pull request

@chilicheech
Copy link
Contributor Author

cool, that seems to work. here's the new discovery payload. notice the name:

{
  "type": "light",
  "object_id": "dimmer",
  "discovery_payload": {
    "schema": "template",
    "brightness_template": "{{ (value_json.value / 99 * 255) | round(0) }}",
    "state_topic": "z2m/2/38/0/currentValue",
    "state_template": "{{ \"off\" if value_json.value == 0 else \"on\" }}",
    "command_topic": "z2m/2/38/0/targetValue/set",
    "command_on_template": "{{ ((brightness / 255 * 99) | round(0)) if brightness is defined else 255 }}",
    "command_off_template": "0",
    "device": {
      "identifiers": [
        "zwavejs2mqtt_0xc5b5c9e5_node2"
      ],
      "manufacturer": "Zooz",
      "model": "Dimmer Paddle Switch (ZEN22)",
      "name": "patio_lights",
      "sw_version": "3.5"
    },
    "name": "patio_lights_dimmer",
    "unique_id": "zwavejs2mqtt_0xc5b5c9e5_2-38-0-currentValue"
  },
  "discoveryTopic": "light/patio_lights/dimmer/config",
  "values": [
    "38-0-currentValue",
    "38-0-targetValue"
  ],
  "persistent": false,
  "ignoreDiscovery": false,
  "id": "light_dimmer"
}

no more dash in the beginning. and verified the name is correct in HASS as well.

thanks for this fix

@varet80
Copy link
Collaborator

varet80 commented Jan 12, 2021

I have created a pull request, We will need to discuss if this is the best way (for this moment) to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants