RogerSelwyn / mqtt_discoverystream_ha

Extension of HA mqtt_statestream integration with discovery config publishing
3 stars 5 forks source link

Help needed #9

Closed pergolafabio closed 5 months ago

pergolafabio commented 5 months ago

Hey @RogerSelwyn , i really like this integration, cause i can now control entities on another dashboard i use I have configured your intergation with a base topic "hikvisiion", in MQTT explorer i can see all entities , i can also control them with this command for example :

mosquitto_pub -h localhost -p 1883 -t "hikvision/light/badkamer/set_light" -m '{ "state": "ON" }'

Now , my question, its not related to this integration, since its working fine, but i use "HomeHabit", it also offers an MQTT integration, i created a button like below there, but for some reason , it doesnt do anything, i'm not an expert in MQTT, thats why i wanted to ask if you can see what i'm doing wrong? im also not sure where i need to add the payload, is it to publish or subscribe?

        "name": "Bad Mqtt",
          "type": "light",
          "lightType": "switch",
          "subscribe": {
            "topic": "hikvision/light/badkamer/state",
            "filter": {
              "type": "none"
            },
            "value": {
              "payload": "json",
              "path": "",
              "map": {
                "on": "{\"state\": \"ON\"}",
                "off": "{\"state\": \"OFF\"}"
              }
            }
          },
          "publish": {
            "topic": "hikvision/light/badkamer/set_light",
            "payload": {
              "map": {
                "on": "{\"state\": \"ON\"}",
                "off": "{\"state\": \"OFF\"}"
              }
            },
            "retain": false
          },
          "qos": 0
        }
RogerSelwyn commented 5 months ago

I'm not quite sure what the code you have provided is. It looks like JSON but I'm not quite sure what it is trying to do. Where are you sending that json to?

pergolafabio commented 5 months ago

Hi, thnx advance, appreciate it,, that JSON, is just the export of the "homehabit" tool, here are screenshots, where i enabled mqtt and created an entity with the UI builder ...

Screenshot_20240328-160101

Screenshot_20240328-160120 Screenshot_20240328-160128 Screenshot_20240328-160130 Screenshot_20240328-160133

pergolafabio commented 5 months ago

you can see in subscribe/publish,, the payload is empty, but its not svisible there, but i used this one to send on/off

                "on": "{"state": "ON"}",
                "off": "{"state": "OFF"}"
RogerSelwyn commented 5 months ago

Sorry, I don't use HomeHabit so no idea what that is trying to do. There are some diagrams on the home page of this repository which may help you in understanding along with looking at the MQTT messages from your system plus the following links:

  1. https://www.home-assistant.io/integrations/mqtt/
  2. https://www.home-assistant.io/integrations/light.mqtt/ - linked from 1

In essence you need to send a configuration message to homeassistant topic (discovery topic) which the core MQTT integration picks up and creates the entity. The message also tells core where to subscribe to for state messages (base topic) and where to send commands back to (command topic). You then send messages to the specified base topic, and need to subscribe to commands being returned to the specified command_topic that you then run the appropriate service to configure the entity (which will then send out a state change to be processed out over MQTT).

Here is a typical config message, sent to (debiandev-discovery)homeassistant/light/bedside_light/config:

{
   "uniq_id":"mqtt_light.bedside_light",
   "obj_id":"bedside_light",
   "stat_t":"debiandev/light/bedside_light/state",
   "avty":[
      {
         "topic":"debiandev/light/bedside_light/availability"
      }
   ],
   "avty_mode":"latest",
   "name":"light",
   "cmd_t":"debiandev-command/light/bedside_light/set_light",
   "schema":"JSON",
   "brightness":true,
   "effect":true,
   "effect_list":[
      "None",
      "candle"
   ],
   "supported_color_modes":[
      "color_temp"
   ],
   "dev":{
      "mf":"Signify Netherlands B.V.",
      "mdl":"Hue ambiance candle (LTW012)",
      "name":"Bedside Light",
      "sw":"1.108.7",
      "ids":[

      ],
      "cns":[
         [
         ]
      ]
   }
}

This is a typical state sent to debiandev/light/bedside_light/state:

{
   "state":"ON",
   "brightness":68,
   "color_mode":"color_temp",
   "color_temp":428,
   "effect":"None",
   "color":{
      "h":29.343,
      "s":78.812,
      "x":0.564,
      "y":0.389,
      "r":255,
      "g":152,
      "b":54
   }
}

And a command sent to debiandev-command/light/bedside_light/set_light:

{
   "state":"ON",
   "effect":"candle"
}
pergolafabio commented 5 months ago

ok, thnx , i now started easier, added a switch, like below, seems switches are different then lights? raw vs json? I also see in mqtt explorer a switch is in raw and a light in json ?

cause below is working for the state AND the publish

          "name": "Bureau",
          "type": "switch",
          "subscribe": {
            "topic": "hikvision/switch/bureau_sc/state",
            "filter": {
              "type": "none"
            },
            "value": {
              "payload": "raw",
              "map": {
                "on": "on",
                "off": "off"
              }
            }
          },
          "publish": {
            "topic": "hikvision/switch/bureau_sc/set",
            "payload": {
              "map": {
                "on": "on",
                "off": "off"
RogerSelwyn commented 5 months ago

you can see in subscribe/publish,, the payload is empty, but its not svisible there, but i used this one to send on/off

                "on": "{"state": "ON"}",
                "off": "{"state": "OFF"}"

To be honest I have no real idea how HomeHabit works and what MQTT server it is using, what are it's messages. MQTT discovery stream works with the core MQTT integration and conforms to the messages defined by that. I would suggest you query in the relevant for HomeHabit.

pergolafabio commented 5 months ago

the switch is now working, like in code above, when sending raw But i think your integration, is using json for light and raw for swirtch ?

image

RogerSelwyn commented 5 months ago

Is will be as described in the links I provided.

pergolafabio commented 5 months ago

ok, need to look again, but i have a good start now, thnx a lot, appreciated!!