visualapproach / WiFi-remote-for-Bestway-Lay-Z-SPA

Hack - ESP8266 as WiFi remote control for Bestway Lay-Z spa Helsinki
GNU General Public License v3.0
305 stars 74 forks source link

FHEM Support ? #307

Closed xGDNAx closed 2 years ago

xGDNAx commented 2 years ago

hello has someone already integrated this into FHEM?

visualapproach commented 2 years ago

You can use MQTT to communicate with FHEM. No idea how though, but it should be doable

xGDNAx commented 2 years ago

Hello, yes, it should definitely work via MQTT, but how? I don't have the experience there, MQTT commands should certainly all run the same way and depend on the system, right? GOOGLE translates for me

chunkysteveo commented 2 years ago

This would be best asking in a FHEM support forum or group chat. MQTT from the Spa controller is universal and can be picked up and managed from any MQTT broker. It would be up to the supporting system (FHEM) to deal with the commands.

Maybe ask the same question in an FHEM online forum, for assistance? We can certainly point you to where you would enter your MQTT broker details, and what the spa sends via MQTT, but I don't think anyone here has used FHEM?

Steve

xGDNAx commented 2 years ago

Hello, sorry for the late reply.

I don't have all the parts there yet and wanted to look for data, but I haven't found what I was looking for 100%.

where can I find a list of the exact MQTT commands? English isn't really my thing, it's really hard for me.

xGDNAx commented 2 years ago

HY I'm still trying MQTT for FHEM, I know the simple MQTT commands. example

Predator/stat/POWER1:.* state

Predator/cmnd/POWER1=1 ON

Predator/cmnd/POWER1=0 OFF

but how are you doing here

visualapproach commented 2 years ago

The available MQTT commands is described in the build instructions but I get that it's not super easy to understand when new to it. But basically you need to publish a message to a topic. To command the layzspa you need to publish a command to the topic "layzspa/command". The command is a JSON string with four key/value pairs. Example '{CMD:0, VALUE:1, XTIME:0, INTERVAL:100}' This will send the command 0 (list of commands in the instructions) with the value 1 (On) to the esp and it will be executed immediately* and repeated every 100s

xGDNAx commented 2 years ago

Sorry, I don't understand anything more, the MQTT structure is completely different from what I know.

`defmod MQTT2_Helsinki MQTT2_DEVICE Helsinki attr MQTT2_Helsinki group Spa attr MQTT2Helsinki readingList Helsinki:layzspa/message:.* { json2nameValue($EVENT, 'message', $JSONMAP) }\ Helsinki:layzspa/times:. { json2nameValue($EVENT, 'times_', $JSONMAP) }\ Helsinki:layzspa/other:. { json2nameValue($EVENT, 'other_', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspatemperature/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspa_targettemperature/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/climate/layzspaclimate/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:layzspa/Status:. Status\ Helsinki:layzspa/MAC_Address:. MAC_Address\ Helsinki:layzspa/MQTT_Connect_Count:. MQTT_Connect_Count\ Helsinki:layzspa/reboot_time:. reboot_time\ Helsinki:layzspa/reboot_reason:. reboot_reason\ Helsinki:layzspa/button:. button\ Helsinki:homeassistant/sensor/layzspa_pressedbutton/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspa_reboottime/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspa_rebootreason/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspassid/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzsparssi/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspaip/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspa_connectcount/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspa_time_totarget/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspaenergy/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspa_chlorineage/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspa_filterage/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspauptime/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspapumptime/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspaheatertime/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/sensor/layzspaairtime/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/binary_sensor/layzspalock/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/binary_sensor/layzspaheater/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/binary_sensor/layzspaready/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/binary_sensor/layzspaconnection/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/switch/layzspa_heatregulation/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/switch/layzspaairbubbles/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/switch/layzspapump/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/switch/layzspa_temperatureunit/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/button/layzspa_resetchlorine/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/button/layzspa_resetfilter/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) }\ Helsinki:homeassistant/button/layzspa_restartesp/config:.* { json2nameValue($EVENT, 'config', $JSONMAP) } attr MQTT2_Helsinki room MQTT2_DEVICE

setstate MQTT2_Helsinki 2022-07-08 13:11:02 IODev MQTT2_FHEM_Server setstate MQTT2_Helsinki 2022-07-08 13:11:46 MAC_Address A8:48:FA:C0:66:63 setstate MQTT2_Helsinki 2022-07-08 13:11:46 MQTT_Connect_Count 3 setstate MQTT2_Helsinki 2022-07-08 13:11:46 Status Alive setstate MQTT2_Helsinki 2022-07-08 13:11:47 button NOBTN setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_action_template {% if value_json.RED == 1 %}heating{% elif value_json.GRN == 1 %}idle{% elif value_json.FLT == 1 %}fan{% else %}off{% endif %} setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_action_topic layzspa/message setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_availability_topic layzspa/Status setstate MQTT2_Helsinki 2022-07-08 13:11:55 config_command_topic layzspa/command setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_current_temperature_template {{ value_json.TMP }} setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_current_temperature_topic layzspa/message setstate MQTT2_Helsinki 2022-07-08 13:11:53 config_device-class connectivity setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_device_class temperature setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_device_configuration_url http://192.168.178.14 setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_device_connections_1_1 mac setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_device_connections_1_2 A8:48:FA:C0:66:63 setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_device_identifiers 12609123 setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_device_manufacturer Visualapproach setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_device_model MIAMI2021 setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_device_name Layzspa WiFi controller setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_device_sw_version 2022-05-24 setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_expire_after 700 setstate MQTT2_Helsinki 2022-07-08 13:11:55 config_icon mdi:restart setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_max_temp 40 setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_min_temp 20 setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_mode_command_template {CMD:3,VALUE:{%if value == "heat" %}1{% else %}0{% endif %},XTIME:0,INTERVAL:0} setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_mode_command_topic layzspa/command setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_mode_state_template {% if value_json.RED == 1 %}heat{% elif value_json.GRN == 1 %}heat{% else %}off{% endif %} setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_mode_state_topic layzspa/message setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_modes_1 fan_only setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_modes_2 off setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_modes_3 heat setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_name Layzspa temperature control setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_payload_available Alive setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_payload_not_available Dead setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_payload_off {CMD:4,VALUE:0,XTIME:0,INTERVAL:0} setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_payload_on {CMD:4,VALUE:1,XTIME:0,INTERVAL:0} setstate MQTT2_Helsinki 2022-07-08 13:11:55 config_payload_press {CMD:6,VALUE:true,XTIME:0,INTERVAL:0} setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_power_command_topic layzspa/command setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_precision 1 setstate MQTT2_Helsinki 2022-07-08 13:11:49 config_state_class total_increasing setstate MQTT2_Helsinki 2022-07-08 13:11:54 config_state_off 0 setstate MQTT2_Helsinki 2022-07-08 13:11:54 config_state_on 1 setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_state_topic layzspa/message setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_temperature_command_template {CMD:0,VALUE:{{ value|int }},XTIME:0,INTERVAL:0} setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_temperature_command_topic layzspa/command setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_temperature_state_template {{ value_json.TGT }} setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_temperature_state_topic layzspa/message setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_temperature_unit C setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_unique_id climate.layzspa_climate12609123 setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_unit_of_measurement °C setstate MQTT2_Helsinki 2022-07-08 13:21:11 config_value_template {{ value_json.TGT }} setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_AIR 0 setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_BRT 0 setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_CH1 32 setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_CH2 50 setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_CH3 49 setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_CONTENT STATES setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_FLT 1 setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_GRN 0 setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_HJT 0 setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_LCK 1 setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_PWR 1 setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_RED 0 setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_TGT 35 setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_TIME 1657279545 setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_TMP 21 setstate MQTT2_Helsinki 2022-07-08 13:25:46 message_UNT 1 setstate MQTT2_Helsinki 2022-07-08 13:25:46 other_CONTENT OTHER setstate MQTT2_Helsinki 2022-07-08 13:25:46 other_FW 2022-05-24 setstate MQTT2_Helsinki 2022-07-08 13:25:46 other_HASJETS false setstate MQTT2_Helsinki 2022-07-08 13:25:46 other_IP 192.168.178.14 setstate MQTT2_Helsinki 2022-07-08 13:25:46 other_MODEL MIAMI2021 setstate MQTT2_Helsinki 2022-07-08 13:25:46 other_MQTT 0 setstate MQTT2_Helsinki 2022-07-08 13:25:46 other_PressedButton 1b1b setstate MQTT2_Helsinki 2022-07-08 13:25:46 other_RSSI -67 setstate MQTT2_Helsinki 2022-07-08 13:25:46 other_SSID My Home setstate MQTT2_Helsinki 2022-07-08 13:11:47 reboot_reason External System setstate MQTT2_Helsinki 2022-07-08 13:11:46 reboot_time 2022-07-08T11:11:45+0000 setstate MQTT2_Helsinki 2022-07-08 13:11:57 subscriptions layzspa/command setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_AIRTIME 11 setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_CLINT 7 setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_CLTIME 1657126319 setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_CONTENT TIMES setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_COST 0.260593325 setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_FINT 7 setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_FTIME 1657126321 setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_HEATINGTIME 92 setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_JETTIME 0 setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_KWH 0.260593325 setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_MINCLK 15 setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_PUMPTIME 15933 setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_TIME 1657279545 setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_TTTT 8116 setstate MQTT2_Helsinki 2022-07-08 13:25:46 times_UPTIME 58608 `

chunkysteveo commented 2 years ago

You need to learn and understand MQTT from the ground up, and then apply what you have learned to figure out how to pull in information, and push out commands from and to the spa unit.

MQTT is very daunting to get your head around, but when you learn how it is structured, and how it's all setup, you will soon get the hang of it and be able to interpret and break down the messages and commands.

There is a good program - MQTT Explorer - which has helped me see all my network MQTT traffic, and it helps me visualise what and who is talking back and forth. That helped me to understand MQTT structure better.

mqttexplorer-example

See the image above - this is MQTT Explorer - and all the traffic to and from anything to do with "layzspa". Ignore "layzspaADDA" and "homeassistant".

On the left is where all the MQTT topics are being published, you can see the Status = Alive, reboot_time, message, times, etc. There is one there called command - that is the MQTT topic layzspa/command, and it's already been populated with some commands by me pressing the buttons on the ESP8266 web GUI.

On the top right you can see the values of the topics, here I have highlighted the command topic, and you can see the value is a JSON object of:

 {
 "CMD":2,
 "VALUE":0,
 "XTIME":0,
 "INTERVAL":0
 }

Ignore that VALUE is there twice - MQTT Explorer is tracking a change in that value from 1 to 0, red to green - this is how you can see things happening on your network with MQTT.

Your FHEM setup will need to subscribe to at least the topic layzspa/message to get all the info about the states of the pump, heater etc. When something changes on the spa, the MQTT topic will change, e,g, AIR will go from 0 to 1 when the blowers are switched on. In my Home Assistant, I have a switch which watches that value of AIR, and when it goes to a 1 - the "Bubbles" switch in Home Assistant also goes ON.

So bottom right is the "Publish" section. Here is where you can publish things to the topics.... Here is where the commands come in. You are going to publish commands to the Layzspa via the topic layzspa/command. The message (Payload) of this needs to be a JSON object, looking much like:

{"CMD":2,"VALUE":1,"XTIME":0,"INTERVAL":0}

If click publish as per the button in the image above - my blower bubbles will come on! Command = 2, Value = 2 - which in the documentation states the ESP8266 will instruct the spa to turn on the blower fan. Likewise you will lots change in the window on the left as the spa reports back the things have updated - the AIR in the topic layzspa/message will change to 1, as it's saying - "hey - my blowers are on!". That will make my switch in Home Assistant turn on too.

{"CMD":2,"VALUE":0,"XTIME":0,"INTERVAL":0} publish that, and the blowers will turn off. My switch in Home Assistant publishes that command (Payload) to the MQTT topic layzspa/command to turn off the blowers.

So your FHEM will now need to be able to publish MQTT messages to the topic layzspa/command in the JSON format to instruct the spa to do things. Follow the CMD documentation about what command does what.

That's your back and forth from MQTT to and from the Spa ESP8266 unit.

It will make more sense when you have it all hooked up - if you publish a commend to turn on the blowers, and they actually come on, it's magic, and you will smile!!! Doing it as a test with nothing to see change or happen won't encourage you to keep learning.

Install/download MQTT Explorer, sign into your MQTT broker server, and watch and interact with the MQTT topics, and enjoy learning!! Once you have the hang of doing it yourself, you should be able to implement your knowledge into FHEM to create sensors and switches to monitor and interact with your Lay Z Spa.

Steve

xGDNAx commented 2 years ago

THX for Help, its work for Me. Screenshot (20)

but i cant set Temp command = {CMD:0,VALUE:{{ value|int }},XTIME:0,INTERVAL:0} 30 is this right ??

chunkysteveo commented 2 years ago

To set a temperature you would send... {"CMD":0,"VALUE":30,"XTIME":0,"INTERVAL":0} for 30°C. The value has to be an integer i.e. no decimal point, whole numbers (from 20 - 40)

xGDNAx commented 2 years ago

Hy yes, via FHEM I get the slider so I have to find the way how he puts the number in the code for me.

when I set the slider, he doesn't write the number in the code, but at the end

xGDNAx commented 2 years ago

Hy its work for me, not perfekt but its work