As you might figure out I have solved my problems with the RFXtrx-component by taking a detour via mqtt to get it working. Doing so with Node-RED and node-red-contrib-rfxcom. And it works perfect except for lights.
Any way, the state topic are publish correct with a message that is either “On” or “Off”, but Home Assistant is not picking up the state.
If I click On or Off in the UI it sends ON and OFF to the correct topic. And it works. But when I try to update the state with state_topic from Node-RED, nothing happens in the UI.
The attributes topics also works as it should. It is only the state that is not picked up.
If I instead add them as a switch, everything works.
You have specified a state_topicand set optimistic: true. Why?
Normally if you can receive the device’s current state via state_topic there’s no need to use optimistic.
You’ve also specified json_attributes_topic which suggests the device sends its status in JSON format. If that’s true, you will need to specify a value_template to extract the device’s state from the JSON message received via state_topic.
Please post an example of the message published to rfxtrx/AC.0x01A90B56.15/state so we can help you construct an appropriate value_template.
optimistic is set to true because I have no feedback. I am controlling 433MHz devices using mqtt. I might fix a function that sends back that the broker has recived the message, but i still can’t know that the device actually has revived the command.
The state_topic is because the devices can be controlled by 433MHz remote controls, and when they are I want it to be known by Home Assistant. And that is why is send state. Which is not picked up by Home Assistant.
The json_attributes_topic is because some devices send som attributes. Like RSSI. Those are handled by this topic.
Here is all the messages published to rfxtrx/AC.0x01A90B56.15
You say it works when configured as switch but not as light?
In that case, without looking at the source code, my guess is that the light and switch components don’t behave the same way when both optimisticandstate_topic are specified.
Optimistic mode can be forced, even if the state_topic is available. Try to enable it, if experiencing incorrect light operation.
But i found one strange thing. By removing the optimistic: true the presentation change in UI. Before, it had a bulb, like all other lights, but it had no slider for on and off. Instead there was to “lightnings” like a switch for turning on and off. I wonder if that is a “bug”.
I don’t know which version of Home Assistant you’re using but I just tested it in 0.88.1 and switch is case-sensitive (and so is light). Publishing "on" to state_topic fails to activate the switch (in the UI) but "ON" succeeds.
As far as 0.88.1 is concerned, the documentation is correct (default values are ON and OFF).