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

Was support for HomeAssistants MQTT_Json implemented? #630

Closed
jonny190 opened this issue Mar 6, 2018 · 7 comments
Closed

Was support for HomeAssistants MQTT_Json implemented? #630

jonny190 opened this issue Mar 6, 2018 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed home assistant mqtt

Comments

@jonny190
Copy link

jonny190 commented Mar 6, 2018

I can see this was brought up in #235

But from what ive read the auto discover was fixed with no mention of the comparability to use home assistants MQTT_Json (https://home-assistant.io/components/light.mqtt_json/)

I'd live to see the transition feature be implemented over the current ON/OFF functionality

@xoseperez
Copy link
Owner

There are no plans to support MQTT_JSON atm. I will flag this issue as an enhancement. If anyone wants to contribute it will be welcomed.

@xoseperez xoseperez added enhancement New feature or request help wanted Extra attention is needed mqtt home assistant labels Mar 6, 2018
@Skaronator
Copy link
Contributor

I'll take a look since I need transitions as well.

@Skaronator
Copy link
Contributor

@xoseperez
I gave this a try. I got it working but I don't like it how it currently is implemented. The main issue is that I need values from light.ino (RGB, Brightness, Color Temp) in relay.ino (ON/OFF) and vise versa.

I'm somewhat lost. The MQTT Topic is similar to /relay/#/set so you could switch multiple relays. Eg. H801-202/json/0/set and H801-202/json/1/set but it feels like that light.ino is only designed for a single switch?

Moving the data from light.ino to relay.ino works fine. I got the _lighMQTTJSONState() function in light.ino which "sends" the data to relay.ino. But I don't know how I should move data the other way around, from relay.ino to light.ino.

To be more specific I need this value for relay X:

https://github.com/Skaronator/espurna/blob/0f3954ab23100462ab67159f02d3f2ff5c7b6647/code/espurna/relay.ino#L642

in light.mqtt

https://github.com/Skaronator/espurna/blob/0f3954ab23100462ab67159f02d3f2ff5c7b6647/code/espurna/light.ino#L620-L651

I don't even know which relay I should use. light.ino feels like it is written for a single relay?

Here is the current implementation (also check the whole MQTT_JSON branch):
https://github.com/Skaronator/espurna/commit/0f3954ab23100462ab67159f02d3f2ff5c7b6647

Currently missing:

  • Transition time (should be very easy)
  • Send update on color change (see above, lightMQTT function in light.ino)

@xoseperez
Copy link
Owner

xoseperez commented May 3, 2018

I guess the trouble is caused by trying to use the relay module with a light device. It's not your problem, is inherited by ESPurna architecture but I feel this is wrong. The relay module is a first class citizen since everything started with a relay, wifi and MQTT. But there is no reason there should be a relay here.

At the same time the relay is very useful since there are a lot of features on top of it (pulse, scheduling,...). But maybe the light module should have it's own on/off routines...

@Skaronator
Copy link
Contributor

Would be a good point to directly support multiple light switches, maybe even dual RGB or dual CCT strips.

Modifying the MQTT command topics to include a switch id - eg.:

- {root topic}/mired/set
+ {root topic}/0/mired/set
- {root topic}/rgb/set
+ {root topic}/0/rgb/set

So we could set the color temperature of the first CCT strip with {root topic}/0/mired/set and the second CCT strip with {root topic}/1/mired/set. Same for on and off {root topic}/0/switch/set and {root topic}/1/switch/set.

Would be cool to configure the channels directly from the Webinterface (or while compiling). For example:

Channel Type
0 warm white 1
1 cold white 1
2 normal channel
3 warm white 2
4 cold white 2

or dual RGB strip over 6 channels (if there is a device? or somebody build its own)

@Skaronator
Copy link
Contributor

Skaronator commented May 5, 2018

I've updated the code in my fork. The light.ino file has now its own MQTT Topic called "switch". I also change the MQTT Topic of the other light commands in order to support multiple light switch in the future. (And we don't need to have 2 breaking changes between 2 updates)

- red is the old topic
+ green the new topic

- H801-201/relay/0/set
+ H801-201/switch/0/set
- H801-201/brightness/set
+ H801-201/brightness/0/set
- H801-201/rgb/set
+ H801-201/rgb/0/set
- H801-201/mired/set
+ H801-201/mired/0/set

MQTT_JSON support works. The topic is H801-202/json/0/set. The HA config would look like:

  - platform: mqtt_json
    name: H801_202_JSON
    qos: 0
    state_topic: H801-202/json/0
    command_topic: H801-202/json/0/set
    availability_topic: H801-202/status
    payload_available: 1
    payload_not_available: 0
    brightness: true
    rgb: true
    color_temp: true

Code is in the MQTT_JSON branch: https://github.com/Skaronator/espurna/commits/MQTT_JSON

Known Issue:

  • The old H801-201/relay/0/set should be ignored when there are no relays. (Eg. light only) This is just a minor issue.
  • Transition not implemented yet. Done.
  • Switch in Webinterface doesn't work since it still points on the "relay". Not sure what the best way is to know if its a ligh switch or a relay switch.

What do you think @xoseperez?

@xoseperez
Copy link
Owner

I'm worried about the topic naming change since it breaks backwards compatibility. Maybe it should only change if there is indeed more than one light switch.

Also we should be aware than detaching the relay module from the light module we are losing some features, like pulses or MQTT sync...

@mcspr mcspr closed this as completed in 4d157cc Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed home assistant mqtt
Projects
None yet
Development

No branches or pull requests

3 participants