Controlling the LED on a Sonoff independendently from the switch

Hello. I am trying to control the LED on a sonoff independently from the actual switch. I am successful in turning off and on by calling it as a service, but the switch on the light card will turn on the LED, but won’t turn it back off. The GUI switch turns back to off leaving the LED on. Here is how I have the component defined in configuration.yaml:

light 1:
platform: mqtt
name: “Sonoff LED 05”
command_topic: “cmnd/sonoff4/LedPower”
state_topic: “stat/sonoff4/LedPower”
payload_on: “ON”
payload_off: “OFF”
retain: true
optimistic: false

I am using the LED_MQTT function in the user.config.h as follows:

#define APP_LEDSTATE LED_MQTT

And like I said above, I can call the

light.turn_on

and

light.turn_off

service by referring to the

light.sonoff_led_05

entity. I do not know of anything I should be doing differently. Any help is appreciated.

Thanks,
Mike

It sounds like HA isn’t seeing the state message come back from the sonoff.

Get some software like MQTTLens and connect it to your MQTT server. You can then subscribe to your command and state topics to see what is actually being sent and to where.

Out of interest, why are you trying to do this?

I want to use the led circuit on the sonoff for an led on a wall switch. I want it to be on when the switch is off, and off when the switch is on. I also want to control it with the sun above/below horizon.

jivesinger. Thanks for your help. The payload is a json message that looks like:

{
“LedPower”:“OFF”
}

I’m not sure how to deal with that in the configuration.yaml

From

Try adding
state_value_template: "{{ value_json.LedPower }}"

to your light config