Closed jonny190 closed 3 years ago
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.
I'll take a look since I need transitions as well.
@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:
in light.mqtt
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:
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...
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)
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:
H801-201/relay/0/set
should be ignored when there are no relays. (Eg. light only) This is just a minor issue.What do you think @xoseperez?
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...
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