jheling / freeathome

Free@Home component for Home Assistant
103 stars 37 forks source link

Virtual devices are not showing up #108

Open Net-Felix opened 2 years ago

Net-Felix commented 2 years ago

Hi,

i added some Virtual devices to my SysAP. Unfortunatelly those are not showing up in HA.

regards Felix

Tho85 commented 2 years ago

Could you provide a dump of your SysAP configuration as described in the README?

Net-Felix commented 2 years ago

Hi,

here is my Dump: Dump

And this is from monitor when i try to switch a virtual device through sysap webinterface:

<?xml version="1.0" encoding="UTF-8"?>
<project timeStamp="99143" sessionId="cafc3d9" type="update" mrhaVersion="2.6.4" mrhaBuild="8172">
   <privileges>
      <user name="379343b5-a462-4d89-9db7-b76508d555c2@busch-jaeger.de">
         <privilege path="807A7F04E81C" accessLevel="541" />
      </user>
   </privileges>
   <devices>
      <device serialNumber="6000EA57FCF0" domainAddress="1011" state="modified" commissioningState="ready" progress="100">
         <channels>
            <channel state="modified" i="ch0000" cid="60000148">
               <inputs>
                  <dataPoint state="modified" i="idp0000" full="false">
                     <value>1</value>
                  </dataPoint>
               </inputs>
               <outputs />
               <parameters />
               <scenes />
            </channel>
         </channels>
      </device>
   </devices>
</project>

ps: you can find the virtual devices with searching "virt_" as a all gave them this prefix

Tho85 commented 2 years ago

Hi, thanks for the detailed dump.

According to the monitor output, you switched the device with serial number 6000EA57FCF0. This corresponds to a device called virt_licht_garage in your config. As far as I can see, the XML config for virtual devices seems to be very sparse, i.e. there's not much information about the device virt_licht_garage, its channels, datapoints, functions, pairings etc.

This component relies on function IDs and pairing IDs to assign free@home devices to the correct Home Assistant entity (light, switch, climate, binary sensor...) The absence of this information for virtual devices makes it impossible to create the "correct" device in Home Assistant. Integrating these kind of virtual devices into this component would require a major rework of the config parser, without knowing if it is possible at all.

May I ask for which purpose you want to use virtual devices in free@home? I would recommend that you try to setup whatever you want to accomplish through Home Assistant instead of free@home. I bet there's a way to implement your use case without free@home virtual devices.

derjoerg commented 2 years ago

Hi, I have the same problem.

My usecase is the following: I have the 7-inch wall panel. I want to start a HA-Automation, when a specific icon is pressed. I already created an empty scene in fah, it shows up in HA and I can add it to the panel, but I don't see a possibility in HA to check if the icon was pressed on the panel. So I thought I create a virtual device (e.g. BinarySensor) in fah, put it on the panel and maybe this can be tracked by HA.

Or is there another possibility for my usecase?

Thanks in advance Joerg

Net-Felix commented 2 years ago

same here, i got the 10" wall panel and got some external devices that i want to switch with, therefore i created virtual devices that can be displayed on the panel

Tho85 commented 2 years ago

There should be another way to do this, by using the emulated_hue component.

If you configure emulated_hue, Home Assistant will appear as a Philips Hue bridge for other devices on your network. You can then add this simulated Philips Hue brige to your free@home SysAP. After the initial discovery, it looks like this: grafik

The simulated Hue bridge then exposes devices, scenes, scripts etc. from your Home Assistant to free@home: grafik

You should then be able to drop these devices to your floor plan or add them to your wall panel. You may want to take a look at the emulated_hue docs in order to find out how to select which entities to expose to free@home.

A downside of this approach is that everything (scenes, covers, automations etc.) appears as a light bulb in free@home. The virtual devices approach has support for more device classes, however this is not yet implemented in this component.

Bos2023 commented 1 year ago

Just as some feedback on this question:

May I ask for which purpose you want to use virtual devices in free@home? I would recommend that you try to setup whatever you want to accomplish through Home Assistant instead of free@home. I bet there's a way to implement your use case without free@home virtual devices.

In free@home it is possible to connect many other devices and systems that are integrated by using the virtual devices. For example Motionblinds can be connected to free@home and are shown as "native free@home" devices, by using the virtual devices. (yes, you can connect motionblinds directly to HA as well) Till now I have been using free@home and openhab / nodered but very recently switched to HA. In openhab nodered you can easily use the virtual devices to activate certain things or visualise measurements of 3rd party devices in the free@home app by using the virtual devices. Information about the virtual devices can be found here.https://developer.eu.mybuildings.abb.com/fah_cloud/reference/pairingids/

In my openhab / nodered setup I use a free@home virtual device to select the zones I wish to clean and the start / dock mode. I was hoping to eliminate the nodered part, but it seems I will have to continue using it.

derjoerg commented 1 year ago

Hi,

as the emulated-Hue way to work between HA and F@H is currently (6 months I guess) broken I would really like to ask if the "virtual device" way can be checked again.

I'm not python-programmer but I have a deeper understand of pogramming-languages (js, php). I can play around a lot at home if it helps regarding F@H, HA, Hue, scripting and so.

I saw several tutorials to interact with F@H (virtual devices) and OpenHAB and Node-Red, but an integration in HA would be awesome ... even if it will stay an advanced feature with no simple to use WebGUI.

derjoerg commented 1 year ago

Hi,

I just got a working bi-directional communication up between F@H and HA using Node-Red (websocket and Rest-Api) and a virtual device (switch).

:)

Tho85 commented 1 year ago

as the emulated-Hue way to work between HA and F@H is currently (6 months I guess) broken

Why exactly is emulated_hue broken? It works fine for me.

derjoerg commented 1 year ago

Hi,

look e.g. at #144 and the links in one of the comments. So it is not a freeathome-Probleme, it really seems to be that something in HA after 2022.6.7 changed realted to emulated_hue.

KKlausl commented 10 months ago

Hi,

I just got a working bi-directional communication up between F@H and HA using Node-Red (websocket and Rest-Api) and a virtual device (switch).

:)

Hi @derjoerg, Im very interessted in your solution, because I use virtual devices on my 7" panel also to control 3rd party devices via openhab - but I want to (fully) migrate to HA.

in openhab the FH binding allows to integrate vitual devices - so I didnt have to go via nodered. Now maybe - till virtual devices are shown in this integration (see latest issue) - maybe your workaround fits my needs.

Thank you in advance for your efforts... needless to say, I am no specialist in nodered - but I somehow manged, to feed a virtual inverter in FH via openhab/nodered.

derjoerg commented 10 months ago

Hi @KKlausl,

So there are two ways to consider:

  1. Change something in HA and update it in F@H
  2. Change something in F@H and update it in HA

For the first topic (I used a switch for that):

  1. Create an input_boolean helper in HA
  2. Create a virtual device in F@H with the API a. http://[ip-of-sysap]/swagger/fhapi b. /api/rest/virtualdevice/.... c. I set ttl to -1 and used as type: SwitchingActuator d. In the return message you will get a virtual serial number starting with 6000xxx (remember it)
  3. Assign the virtual device in F@H to a room and place it on a panel
  4. Now in Node-Red
  5. I created a "trigger: state" node, which reacted, when the input_boolean got the state "true"
  6. Then I have a "change" node for "true" and for "false"
  7. in the true change node I set msg.payload to 1
  8. in the false change node in set msg.payload to 0
  9. Both "change" nodes resulted in one "http-request" node with basic authentication and method "PUT" a. http://[ip-of-sysap]/fhapi/v1/api/rest/datapoint/00000000-0000-0000-0000-000000000000/[serial-number].ch0000.odp0000

Now the other way round (I use this for bi-directional virtual devices, but also for the doorbell, the fire- and co-alarm, the movement-sensors, and for some automated lights if I can restrict them by a button to stay on)

  1. Create the necessary helper in HA
  2. In Node-Red
  3. Create a "websocket in" node a. ws://[user]:[password]!@[ip-of-sysap]/fhapi/v1/api/ws
  4. Create a "json" node and convert msg.payload to Javascript-Object
  5. Create a "function" node to get only datapoint messages
    
    let result = [];

if (msg.payload["00000000-0000-0000-0000-000000000000"].hasOwnProperty("datapoints")) {

for (let datapoint in msg.payload["00000000-0000-0000-0000-000000000000"].datapoints) {
    result.push([datapoint, msg.payload["00000000-0000-0000-0000-000000000000"].datapoints[datapoint]]);
}

msg.payload = result;

} else { return null; }

return msg;

6. Create a "split" node to have each message in a dedicated payload
7. Now the BIG "function" node
a. Define as much outputs as devices you want to listen to (I e.g. have 22 :) )
b. In the Start tab define which serials you want to listen to

let filters = { "0": { // Bi-Directional Switch "serial": "6000xxxxxxxx", "output": [] "1": { // Doorbell "serial": "ABByyyyyyyyy", "output": [] }, "2": { // CO "serial": "E11223344556", "output": [] "3": { // Light fixed "serial": "ABB223344556", "output": [] } };

context.set("my_filters", filters);

let keys = [];

for (let key in filters) { keys.push(filters[key].serial); }

context.set("my_keys", keys);

c. In the function tab define the logic, just remember, you have to send an array with payloads in the correct order

let payload = msg.payload; let result = []; let needed = false; let filters = context.get("my_filters"); let keys = context.get("my_keys");

let values = payload[0].split("/");

if (keys.includes(values[0])) {

for (let key in filters) {

    if (filters[key].serial == values[0]) {
        needed = true;
        result.push(
            {
                "payload": {
                    "serial": values[0],
                    "channel": values[1],
                    "datapoint": values[2],
                    "value": payload[1]
                }
            }
        );
    } else {
        result.push(null);
    }

}

}

if (needed) { return result; }


8. Now you have to put a "switch" node to each output
a. For a Bi-Directional switch you have to check the datapoint "idp0000" (payload[0].datapoint = "idp0000" and  payload[0].value = "1") and can then use a "call service" node to modify HA
b. For my doorbell I use the following (payload[0].channel = "ch0018" and   payload[0].datapoint = "odp0000" and    payload[0].value = "1") and then modify an input_button
c. For CO (payload[0].datapoint = "odp0000" and payload[0].value = "1") and also an input_button
d. For a fixed light (payload[0].channel = "ch0001" and payload[0].datapoint = "odp0003" and    payload[0].value = "4")

I hope this helps
KKlausl commented 10 months ago

Hi @derjoerg, Thank you very much for your work and expertise and this detailled guide!! I really appreciate your effort!! :) I will try your steps as soon as possible (for the next 10 days I‘m on a boat trip in france:) cant wait for it…

janpschaefer commented 9 months ago

Hey guys could you make it work? on my side virtual devices are exposed to HA which is amazing. But If I try e.g. to activate a switch (actuator) on both sides free@home or HA, the state doesn't change on the other side and goes back to previous state.

KKlausl commented 9 months ago

Hey guys could you make it work? on my side virtual devices are exposed to HA which is amazing. But If I try e.g. to activate a switch (actuator) on both sides free@home or HA, the state doesn't change on the other side and goes back to previous state.

I had a similar problem, which seems to be caused of free@home. Solution was for me, to „tweak“ a Backup File and reload it, see here:[ Link] (https://community.openhab.org/t/busch-jaeger-free-home/31043/559?page=28). Maybe this works for you too - of you have the nerves ;)).

alexio70 commented 4 weeks ago

Hi @KKlausl,

So there are two ways to consider:

  1. Change something in HA and update it in F@H
  2. Change something in F@H and update it in HA

For the first topic (I used a switch for that):

  1. Create an input_boolean helper in HA
  2. Create a virtual device in F@H with the API a. http://[ip-of-sysap]/swagger/fhapi b. /api/rest/virtualdevice/.... c. I set ttl to -1 and used as type: SwitchingActuator d. In the return message you will get a virtual serial number starting with 6000xxx (remember it)
  3. Assign the virtual device in F@H to a room and place it on a panel
  4. Now in Node-Red
  5. I created a "trigger: state" node, which reacted, when the input_boolean got the state "true"
  6. Then I have a "change" node for "true" and for "false"
  7. in the true change node I set msg.payload to 1
  8. in the false change node in set msg.payload to 0
  9. Both "change" nodes resulted in one "http-request" node with basic authentication and method "PUT" a. http://[ip-of-sysap]/fhapi/v1/api/rest/datapoint/00000000-0000-0000-0000-000000000000/[serial-number].ch0000.odp0000

Now the other way round (I use this for bi-directional virtual devices, but also for the doorbell, the fire- and co-alarm, the movement-sensors, and for some automated lights if I can restrict them by a button to stay on)

  1. Create the necessary helper in HA
  2. In Node-Red
  3. Create a "websocket in" node a. ws://[user]:[password]!@[ip-of-sysap]/fhapi/v1/api/ws
  4. Create a "json" node and convert msg.payload to Javascript-Object
  5. Create a "function" node to get only datapoint messages
let result = [];

if (msg.payload["00000000-0000-0000-0000-000000000000"].hasOwnProperty("datapoints")) {

    for (let datapoint in msg.payload["00000000-0000-0000-0000-000000000000"].datapoints) {
        result.push([datapoint, msg.payload["00000000-0000-0000-0000-000000000000"].datapoints[datapoint]]);
    }

    msg.payload = result;
} else {
    return null;
}

return msg;
  1. Create a "split" node to have each message in a dedicated payload
  2. Now the BIG "function" node a. Define as much outputs as devices you want to listen to (I e.g. have 22 :) ) b. In the Start tab define which serials you want to listen to
let filters = {
    "0": { // Bi-Directional Switch
        "serial": "6000xxxxxxxx",
        "output": []
   "1": { // Doorbell
        "serial": "ABByyyyyyyyy",
        "output": []
    },
    "2": { // CO
        "serial": "E11223344556",
        "output": []
    "3": { // Light fixed
        "serial": "ABB223344556",
        "output": []
    }
};

context.set("my_filters", filters);

let keys = [];

for (let key in filters) {
    keys.push(filters[key].serial);
}

context.set("my_keys", keys);

c. In the function tab define the logic, just remember, you have to send an array with payloads in the correct order

let payload = msg.payload;
let result = [];
let needed = false;
let filters = context.get("my_filters");
let keys = context.get("my_keys");

let values = payload[0].split("/");

if (keys.includes(values[0])) {

    for (let key in filters) {

        if (filters[key].serial == values[0]) {
            needed = true;
            result.push(
                {
                    "payload": {
                        "serial": values[0],
                        "channel": values[1],
                        "datapoint": values[2],
                        "value": payload[1]
                    }
                }
            );
        } else {
            result.push(null);
        }

    }

}

if (needed) {
    return result;
}
  1. Now you have to put a "switch" node to each output a. For a Bi-Directional switch you have to check the datapoint "idp0000" (payload[0].datapoint = "idp0000" and payload[0].value = "1") and can then use a "call service" node to modify HA b. For my doorbell I use the following (payload[0].channel = "ch0018" and payload[0].datapoint = "odp0000" and payload[0].value = "1") and then modify an input_button c. For CO (payload[0].datapoint = "odp0000" and payload[0].value = "1") and also an input_button d. For a fixed light (payload[0].channel = "ch0001" and payload[0].datapoint = "odp0003" and payload[0].value = "4")

I hope this helps

Hi https://github.com/derjoerg What a great suggestion to get the interaction between HA and F@H improved; I am having an issue getting step 7 with the BIG "function' to have the correct syntax; Node Red is reporting an issue; would you mind re-checking your example code "In the Start tab" ? and advice what you mean with the function TAB (you mean the "On Message" tab ?? THX

derjoerg commented 4 weeks ago

Hi @alexio70, I just recognized that I forgot two closing brackets:

Here is the corrected code for the "On Start" tab (and yes, with function tab I mean "On Message"):

let filters = {
    "0": { // Bi-Directional Switch
        "serial": "6000xxxxxxxx",
        "output": []
    },
    "1": { // Doorbell
        "serial": "ABByyyyyyyyy",
        "output": []
    },
    "2": { // CO
        "serial": "E11223344556",
        "output": []
    },
    "3": { // Light fixed
        "serial": "ABB223344556",
        "output": []
    }
};

context.set("my_filters", filters);

let keys = [];

for (let key in filters) {
    keys.push(filters[key].serial);
}

context.set("my_keys", keys);
alexio70 commented 4 weeks ago

Hi https://github.com/derjoerg What a great suggestion to get the interaction between HA and F@H improved; I am having an issue getting step 7 with the BIG "function' to have the correct syntax; Node Red is reporting an issue; would you mind re-checking your example code "In the Start tab" ? and advice what you mean with the function TAB (you mean the "On Message" tab ?? THX

alexio70 commented 4 weeks ago

Hi https://github.com/derjoerg Many many thanks for your swift reply; that really helped me a lot !! Mvg Alexio