Skip to content

Add new config variable to MQTT light#9304

Merged
pvizeli merged 3 commits into
home-assistant:devfrom
belyalov:mqtt_light_rgb
Sep 5, 2017
Merged

Add new config variable to MQTT light#9304
pvizeli merged 3 commits into
home-assistant:devfrom
belyalov:mqtt_light_rgb

Conversation

@belyalov
Copy link
Copy Markdown
Contributor

@belyalov belyalov commented Sep 5, 2017

Description: MQTT Light - New config variable rgb_command_template

Some devices do not understand Home Assistance default RGB format. The idea of this PR is to let user ability to control RGB color format in the same way as variables like rgb_value_template do.

**Pull request in home-assistant.github.io with documentation: PR 3312

Example entry for light.yaml:

Use HEX RGB color format:

light:
  platform: mqtt
  name: "Office Light RGB"
  state_topic: "office/rgb1/light/status"
  command_topic: "office/rgb1/light/switch"
  rgb_state_topic: "office/rgb1/rgb/status"
  rgb_command_topic: "office/rgb1/rgb/set"
  rgb_command_template: "{{ '#%02x%02x%02x' | format(red, green, blue)}}"
  qos: 0
  payload_on: "on"
  payload_off: "off"

Topic message will be like #ffddee

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

@homeassistant
Copy link
Copy Markdown
Contributor

Hi @belyalov,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

Comment thread homeassistant/components/light/mqtt.py Outdated

rgb_color_str = '{},{},{}'.format(*kwargs[ATTR_RGB_COLOR])
tpl = self._templates[CONF_RGB_COMMAND_TEMPLATE]
if tpl is not None:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use:

if tpl...:
    ...
   rgb_color_str = ...
else:
   rgb_color_str = ...

Comment thread homeassistant/components/light/mqtt.py Outdated
colors = {'red', 'green', 'blue'}
env = {}
for key, val in zip(colors, kwargs[ATTR_RGB_COLOR]):
env[key] = val
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this in same statment:

variables = {key: val for key, val in zip(...)}

@belyalov
Copy link
Copy Markdown
Contributor Author

belyalov commented Sep 5, 2017

Pascal, thank you for review.
I've addressed your issues.

@dale3h dale3h added this to the 0.53 milestone Sep 5, 2017
@pvizeli
Copy link
Copy Markdown
Member

pvizeli commented Sep 5, 2017

@pvizeli pvizeli merged commit 9ade800 into home-assistant:dev Sep 5, 2017
@balloob balloob mentioned this pull request Sep 7, 2017
@balloob balloob removed this from the 0.53 milestone Sep 7, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Dec 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants