Kejszijo
(Zoltán Kovács)
August 8, 2017, 6:50pm
1
Hi!
I try to configure the MQTT connection between Home Assistant and HomeGenie. HomeGenie is the MQTT server, and publish 1 light switch. I can see the communication between each other with MQTT.fx program. So I can figure out, how can I control the light switch from Home Assitant. It works fine. This is the config:
light:
platform: mqtt
name: “teszt light”
state_topic: “hg_master/HomeAutomation.NetworkRelays/1/event”
command_topic: “ha_master/MQTT.Listeners/hg_master/command”
state_value_template: “{{ value_json.Value }}”
qos: 0
payload_on: “{ ‘Domain’: ‘HomeAutomation.NetworkRelays’, ‘Address’ : ‘1’, ‘Command’ : ‘Control.On/undefined’ }”
payload_off: “{ ‘Domain’: ‘HomeAutomation.NetworkRelays’, ‘Address’ : ‘1’, ‘Command’ : ‘Control.Off/undefined’ }”
optimistic: true
I’d like to read the light status. The topic is:
And the value:
{“Name”:“Status.Level”,“Value”:"0 ",“Description”:“”,“FieldType”:“”,“UpdateTime”:“2017-08-08T17:31:21.784735Z”,“NeedsUpdate”:false}
If the Value = 0 the light is off, if Value = 1, the light is on.
How can I read the light status (on/off) from this topic?
Kejszijo
(Zoltán Kovács)
August 15, 2017, 1:13pm
2
Hi!
Can somebody help to me? I can’t figure out, how can I read the switch state
Thanks!
gpbenton
(Graham)
August 15, 2017, 3:15pm
3
I believe the MQTT Template Light will do what you need, but I have never used it so this is something of a guess
light:
- platform: mqtt_template
command_topic: "ha_master/MQTT.Listeners/hg_master/command"
command_on_template: "{ ‘Domain’: ‘HomeAutomation.NetworkRelays’, ‘Address’ : ‘1’, ‘Command’ : ‘Control.On/undefined’ }"
command_off_template: "{ ‘Domain’: ‘HomeAutomation.NetworkRelays’, ‘Address’ : ‘1’, ‘Command’ : ‘Control.Off/undefined’ }"
state_topic: "hg_master/HomeAutomation.NetworkRelays/1/event"
state_template: "{{ value_json.Value }}"
I’m not sure about the state_template resulting in 0 or 1 though. For the mqtt_light you have to add
payload_off: 0
payload_on: 1
but they aren’t listed as parameters for the template light, so I don’t know if that will work.
Edit 2:
You might be able to do something like
state_template:
{% if value_json.Value == 1 -%}
"on"
{% else -%}
"off"
{% endif -%}
but this is way beyond my templating experience.
Kejszijo
(Zoltán Kovács)
August 21, 2017, 8:56pm
4
Thanks for your help!
I try your suggestion, but unfortunately it can’t read light state. Control works fine.
My config:
light:
- platform: mqtt_template
name: "teszt light"
command_topic: "ha_master/MQTT.Listeners/hg_master/command"
command_on_template: "{ 'Domain': 'Relays.NetworkRelays1', 'Address' : '2', 'Command' : 'Control.On/undefined' }"
command_off_template: "{ 'Domain': 'Relays.NetworkRelays1', 'Address' : '2', 'Command' : 'Control.Off/undefined' }"
state_topic: "hg_master/Relays.NetworkRelays1/2/event"
state_template: >-
{% if value_json.Value == "1" %}"ON"
{% else %}"OFF"
{% endif %}
payload_on: "ON"
payload_off: "OFF"
optimistic: true
I try payload on=1, payloadon=“1”, payload on=“ON”, payload on=ON, and value_json.Value==1, value_json.Value==“1”, but nothing change
Kejszijo
(Zoltán Kovács)
August 22, 2017, 7:29am
5
In the log I received this message:
2017-08-22 09:28:40 WARNING (MainThread) [homeassistant.components.light.mqtt_template] Invalid state value received
Kejszijo
(Zoltán Kovács)
August 22, 2017, 6:26pm
6
Unfortunately the mqtt_template not working well. But I figured out the other solution. In HomeGenie, I modify the MQTT program. Added the “state” topic which return the same parameter as the command topic.
payload_on: { ‘Domain’: ‘Relays.NetworkRelays1’, ‘Address’ : ‘1’, ‘Command’ : ‘Control.On/undefined’ }
payload_off: { ‘Domain’: ‘Relays.NetworkRelays1’, ‘Address’ : ‘1’, ‘Command’ : ‘Control.Off/undefined’ }
So in this case it works fine with simple mqtt component.
1 Like