[SOLVED] MQTT state does not change in Home Assistant from FHEM

Begonnen von frank.j@me.com, 01 Februar 2022, 23:56:59

Vorheriges Thema - Nächstes Thema

frank.j@me.com

Hi all,

I have successfully set up a mosquito MQTT server, and I can control a light in FHEM via the Home assistant. When I change the state in HA, the state in FHEM changes correctly, and the light switches on and off.

When I switch the light on via a FTM55 switch or in FHEM direct however, the icon in HA does not change (the light is not indicated to be on in the HA dashboard.

So apparently HA does not see the state correctly, what am I doing wrong?

configuration.yaml in HA:
light:
  - platform: mqtt
    schema: template
    name: "Vogels"
    command_topic: "enocean/FSR14_1_2/set"
    state_topic: "enocean/FSR14_1_2/state"
    command_on_template: "on"
    command_off_template: "off"



Code in FHEM:

define FSR14_1_2 EnOcean FF95270E
setuuid FSR14_1_2 5e2d7ee7-f33f-8300-12f3-8b29df4a7cf33adc
attr FSR14_1_2 userattr lightSceneParamsToSave lightSceneRestoreOnlyIfChanged:1,0
attr FSR14_1_2 IODev TCM310_0
attr FSR14_1_2 alias Vogels
attr FSR14_1_2 devStateIcon on:light_light_dim_100@orange dim:light_light_dim_50@green off:light_light@blue
attr FSR14_1_2 eep A5-38-08
attr FSR14_1_2 fp_bg 490,383,0,FSR14_1_2,
attr FSR14_1_2 group 2 Eetkamer
attr FSR14_1_2 gwCmd switching
attr FSR14_1_2 manufID 00D
attr FSR14_1_2 mqttDefaults base={"/enocean/FSR14_1_2"}
attr FSR14_1_2 mqttPublish state:topic={"enocean/FSR14_1_2/state"}
attr FSR14_1_2 mqttSubscribe state:stopic={"enocean/FSR14_1_2/set"}
attr FSR14_1_2 room BGG,Homekit
attr FSR14_1_2 subDef FFB87A06
attr FSR14_1_2 subType gateway



This is the message as received by the MQTT server:

Bericht 4 ontvangen op enocean/FSR14_1_2/state om 23:59:
on
QoS: 0 - Retain: false


Beta-User

Imo FHEM/MQTT_GENERIC_BRIDGE is doing what it is expected to do according to the message you have shown: Send out the state to the configured topic when switched.

So this seems more liekly to be more a Problem on the HomeAssistant side. Perhaps the "payload_on" etc. is missing as mentionned in https://forum.fhem.de/index.php/topic,115279.msg1147334.html#msg1147334
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

frank.j@me.com

I managed to fix it with help from above:

The HomeAssistant code needs a state template in my case:

  - platform: mqtt
    schema: template
    name: "Wastafel"
    command_topic: "enocean/1_b1/set"
    state_topic: "enocean/1_b1/state"
    command_on_template: "on"
    command_off_template: "off"
    state_template: "{% if value == 'on' %}on {% else %} off {% endif %}"