petro
(Petro)
July 31, 2023, 2:34pm
21
also, please post the result of the state_topic here after sending the turn on command and after sending the turn off command. You can use MQTT explorer.
I’d expect something like this would really be what your configuration should be:
- name: JBL Speaker Switch
state_topic: "tele/ZigBee_Bridge/29C3/SENSOR"
command_topic: "cmnd/ZigBee_Bridge/ZbSend"
state_on: 1
state_off: 0
payload_on: '{"device": "JBL_Speaker_Switch","send":{"Power":1}}'
payload_off: '{"device": "JBL_Speaker_Switch","send":{"Power":0}}'
qos: 2
retain: false
then you’d make a template switch that uses your bluetooth speaker as a value_template in combination with the jbl speaker switch
tom_l
July 31, 2023, 2:48pm
22
Already asked that: MQTT Switch - Unknown State - #6 by PickOne
There is no “power”:0 message.
1 Like
petro
(Petro)
July 31, 2023, 3:04pm
23
if that’s the case then…
- name: JBL Speaker Switch
state_topic: "tele/ZigBee_Bridge/29C3/SENSOR"
command_topic: "cmnd/ZigBee_Bridge/ZbSend"
state_on: 1
state_off: 0
value_template: "{{ value_json.ZbReceived.JBL_Speaker_Switch.Power }}"
payload_on: '{"device": "JBL_Speaker_Switch","send":{"Power":1}}'
payload_off: '{"device": "JBL_Speaker_Switch","send":{"Power":0}}'
qos: 2
retain: false
petro
(Petro)
July 31, 2023, 3:42pm
25
then what is going to be sent to the command topic when pressing turn off? Gotta send something.
Otherwise this should be an MQTT command, MQTT binary_sensor combined with a template switch.
tom_l
July 31, 2023, 3:45pm
26
The same power 1 message. Hence the need to use a template to observe another attribute to determine the state.
It’s a switchbot. You send the message and it moves its robot finger then resets. The bot mechanism is monostable. It does not have two states.
Think of a garage remote where you press the same button to open and close it.
petro
(Petro)
July 31, 2023, 3:48pm
27
if it’s momentary, then it should be a mqtt button or mqtt command, he should not be using an MQTT switch as it’s not designed to handle any of this.
petro
(Petro)
July 31, 2023, 3:49pm
28
I recommend a mqtt button, combined with a template switch that presses the button for the on/off command. The state is pulled from the bluetooth being on/off
1 Like
tom_l
July 31, 2023, 3:49pm
29
The thing he is controlling with the switchbot does have two states though, so a switch kind of fits.
tom_l
July 31, 2023, 3:50pm
30
Yeah that would be better.
petro
(Petro)
July 31, 2023, 3:52pm
31
Yeah that makes sense. The problem with an MQTT Switch is that it doesn’t have built in things like “delay_off” or things like that with optimistic mode. Which is what he’d need. So the state of the switch will always be… odd.
I had the electricity off till now :))) Sorry.
So, what should I do in this case, in order to make a working switch for this purpose?
petro
(Petro)
July 31, 2023, 3:58pm
33
mqtt:
button:
- name: JBL Speaker Momentary Switch
command_topic: "cmnd/ZigBee_Bridge/ZbSend"
command_template: >
{{ {"device": "JBL_Speaker_Switch","send":{"Power":1}} | to_json }}
and
- platform: template
switches:
jbl_speaker_switch:
name: JBL Speaker Switch
value_template: >
{{ is_state_attr('sensor.variable_home_tablet_media_volume', 'bluetooth', 'connected') }}
turn_on:
service: button.press
target:
entity_id: button.jbl_speaker_momentary_switch
turn_off:
service: button.press
target:
entity_id: button.jbl_speaker_momentary_switch
1 Like
It is working flawless, thank you!
1 Like