Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

[question] How to handle unusual device values with home assistant discovery. #739

Closed
joshkay opened this issue Sep 23, 2020 · 10 comments · Fixed by #741
Closed

[question] How to handle unusual device values with home assistant discovery. #739

joshkay opened this issue Sep 23, 2020 · 10 comments · Fixed by #741
Assignees
Labels
question Further information is requested

Comments

@joshkay
Copy link

joshkay commented Sep 23, 2020

I'm trying to implement a control for my innovelli led bar. The switch is expecting the brightness value to be one of 0%, 10%, 20% etc. I cannot see a way to accomplish this using the default MQTT light schema.

Instead, I have managed to implement it using the template MQTT light schema. I have this working using the template schema, but I cannot implement the RGB portion using that schema because it doesn't support RGB commands on a separate topic.

I have setup the custom device in customDevices.json. Below is the config:

{
    "798-1-1": [
        {
            "type": "light",
            "object_id": "led",
            "values": ["112-1-13", "112-1-14"],
            "discovery_payload": {
                "schema": "template",
                "command_topic": "112-1-14",
                "command_on_template": "{{ (brightness / 255 * 10) | round(0) if brightness is defined else 5 }}{{0}}{{'%'}}",
                "command_off_template": "0%",
                "state_topic": "112-1-14",
                "state_template": "{{ 'off' if value_json.value == '0%' else 'on' }}",
                "brightness_template": "{{ value_json.value | regex_replace(find='%', replace='', ignorecase=False) | round(0) / 100 * 255 }}"
            }
        }
    ]
}

I'm wondering if there's a way to handle converting the brightness & rgb values on the zwave2mqtt side of things so it can accept a standard request from home assistant.

@joshkay joshkay added the question Further information is requested label Sep 23, 2020
@robertsLando
Copy link
Member

@joshkay Have you tried to ask home assistant for a feature request? I mean, adding rgb commands on a separete topic?

@joshkay
Copy link
Author

joshkay commented Sep 23, 2020

I brought it up on Discord and they told me to use their implementation of OZW. So I thought I'd see what your opinion was before pressing the issue with them. Thoughts?

@robertsLando
Copy link
Member

How do you expect me to send that value? What's the format you need?

@joshkay
Copy link
Author

joshkay commented Sep 23, 2020

I was looking for a way to process the incoming/outgoing mqtt messages before sending the zwave command.

For example, if a brightness set command is sent and the value is 0-10, i would need to convert that to a string and add a % sign to the end of it before sending that command to the zwave device for it to respond properly.
Same thing with getting the value of the brightness, but in reverse. Remove the % sign and send the number alone.

Dealing with the RGB values is a lot more complex, because the device just represents it as a single number from 0-255. It looks like it represents the hue range.

Maybe there could be a way to have custom js function that could convert the values?

Just throwing out ideas.

@robertsLando
Copy link
Member

Maybe there could be a way to have custom js function that could convert the values?

That could be the way. I could add a field to convert the value when publishing and one to convert the value when reading, what about this?

robertsLando added a commit that referenced this issue Sep 24, 2020
@robertsLando robertsLando linked a pull request Sep 24, 2020 that will close this issue
@robertsLando
Copy link
Member

@joshkay I have implemented this. Will merge soon :)

Schermata da 2020-09-24 10-08-30

@joshkay
Copy link
Author

joshkay commented Sep 24, 2020

@robertsLando Wow that's amazing! Thanks

@joshkay
Copy link
Author

joshkay commented Sep 24, 2020

Would it be possible to store this to the devices file? This way if other people are looking to implement an Inovelli Red Switch in the future with home assistant it would just work for them without needing to add these functions to the gateway values table?

This implementation should work just fine for me, but I'm wondering if there's a better way for this to work out of the box for new users (for these strange devices).

@robertsLando
Copy link
Member

It would be difficult to add that to a device template, for a design reason, because when a value it's published to mqtt, the gateway publish it without knowing if there is a discovered device/value associated

@joshkay
Copy link
Author

joshkay commented Sep 24, 2020

Okay no problem. Just food for thought.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants