[APP][Pro] The Things Network - Make Homey part of a global LoRaWAN Network

Just to again confirm all is still working well since the v0.03 update
Thankyou

Hi @Leo838 I installed the app today and used the Homey webhook template in thethingsstack. This didnt work… So I added it as custom webhook manually, and that did work.

So I guess the template is wrong somehow.

Anyway, thx 4 the app!

I’ve submitted a patch to TTN to fix the template, it should be corrected in a few days.

Obviously only messages from the end devices to Homey (i.e. uplink) are handled now. I’m working on downlink messages but I need to implement drivers , devices etc so more complicated. This is my first app & first experience working with JavaScript so might be a while…

2 Likes

Super. I was just about to ask you about that. I would like to have a device driver for my LoRa GPS tracker and was just thinking about how to do this in combination with your app.

I think it should be possible to have ‘generic’ device drivers, without the need to add a driver for each individual brand and device type. E.g. my dragino tracker could be added to Homey as a generic tracker with lat/lon info. Other generic LoRa devices in Homey could be for instance:

  • Door/Window sensor
  • Humidity sensor
  • Rain sensor
  • Wind sensor
  • Motion sensor
  • Generic Alarm
  • GPS location
  • … (we have to come up with a more comprehensive list, the default Homey capabilities are a good starting point)

Each device type will have one or more Homey capabilities. My Dragino tracker also has an alarm button, so to keep things generic in Homey I could add it as two devices: a GPS tracker and a generic Alarm device.

Downlink is a different issue. The commands are very brand and device specific. So I would stick to letting the Homey users enter the raw hex commands in a flow card.

But is it possible to have downlink with the webhook interface? I think you need the MQTT interface for that, right? Edit: I see that there is an API available for this. So that should work :partying_face:

As said, I want to have my Dragino tracker in Homey anyway. I could make my own app for that, but I would rather have an aligned development with you and keep things a bit more generic (= brand independent) so that everybody can use it.

I will reach out to you on slack to discuss this.

2 Likes

I’ve just uploaded a development version of the new app but a lot of features are unfinished & some broken. However it may give you an idea of where I’m heading. I’ve added a device on my app & it successfully sends a downlink (simple on or off). The README.md contains details of how to add an end device as a Homey device & at the bottom of the README.md you’ll see an example of a compatible downlink formatter.

Please note that the Homey webhook template in the TTN console is now working & should be used as it creates & implements a downlinkey which is critical.

Expect slow progress on this for the next few weeks as my consultation business is getting a little busier…

3 Likes

Owen im so glad that you started doing this app… With the app viritual devices i can get my lora temp and hum sensor in the dashbord and getting graphed! :slight_smile: Excellent work!!!
bild

Is it possible to change so the payload from ttn wont have to send state1 and state2 and maybe even that the name value1 and value2 possible to change in the app?

I having problem with this because i also have to send the payload to tago.io (same payload för all webhooks) and that makes unnecessary logging of the unused variables that i dont need…

Peter,

Great to hear the app is useful for you.

With regards to the data variables & names I’m in the process of rewriting the app to facilitate downlinks & user defined capabilities per device. There’s a good bit of work in it & my paying job has gotten busier so this has taken a back seat. When I get time I’ll continue the development but in the meantime if you’ve any coding experience it would he straightforward enough to download, modify, compile & install your own version of the app.

Regards,

1 Like

Take your time Owen! Work should always come first! Im so glad that people like you exist. You makes this communtiy and also homey so great with your app!

I´ve tried to modify but failed :crazy_face: But i will try again! :slight_smile:

Hi all,

Just wanted you to know that I have been working on extending Owens work. It enables to ad any public Gateway to Homey. With that you can get an alarm when the gateway goes offline, and you can gather transmit and receive statistics.

I use it to gather RX/TX statistics for my own gateway, so I can experiment with the location of my gateway and a different antenna. My assumption is that the average TX/RX figures will go up when I use a higher gain antenna, and place it at a better spot.

At the moment this app version is only available in my own Github repo. But I hope that Owen is able to merge and release it to the app store :slight_smile:

2 Likes

@Gruijter Nice work… Could you please make a short list what i need to do to install it with cli? I have done install thru cli earlier on other apps so not it isnt info about “homey app install” i need. I think the problem i have is with the webhook. I have tried to create the file env.json with info i got from dev page… But where do i get the $key? The settings html info seams static so thats no help… :slight_smile:

Hello Owen/Peter/Others,

Thank you for your work on getting TTN to work with Homey!

I took the plunge this week and bought a Lorawan gateway and a (Milesight LoRaWAN EM300 Temperature) sensor and can see “forward uplink data message” with payload data on my TTN app console.

However, my Homey flow, created to receive data, is never triggered. (Similar to Kevin here: The Things Network - Make Homey part of a global LoRaWAN Network (test available) - #13 by xAPPO)

I have tried the “none”, “device repository”, “cayenne payload” formatters, even custom java (from here: SensorDecoders/EM300_Series/EM300-TH at master · Milesight-IoT/SensorDecoders · GitHub ), but I did not ever get it to trigger/work.

More info:

  • I installed de most recent TTN homey app
  • Created the homey webhook throug the homey template on TTN
  • Enabled all event types for this webhook
  • Built a homey flow, with a TTN app “Uplink Message from TTN” card, to send me a push notification with all variable data

That flow has never triggered :frowning:

My Objective: Get data into a virtual homey temperature sensor, like Peter did here: The Things Network - Make Homey part of a global LoRaWAN Network (test available) - #26 by Peter_Johansson

Can you share what you have done to get a homey flow to trigger?

(And/or get that data into a virtual sensor?)

Much appreciated in advance!
@Leo838 @Peter_Johansson @xAPPO

Sure thing i can help you! :slight_smile:

First i modified the uplink decoder on ttn under the device in payload formaters/uplink/custom Javascript formatter. I did this because @Leo838 app only listen to value1, value2, state1 and state2

function Decoder(bytes, port) {
    var decoded = {};

    for (var i = 0; i < bytes.length;) {

        var channel_id = bytes[i++];

        var channel_type = bytes[i++];

        // BATTERY

        if (channel_id === 0x01 && channel_type === 0x75) {

            decoded.battery = bytes[i];

            i += 1;

        }

        // TEMPERATURE

        else if (channel_id === 0x03 && channel_type === 0x67) {

            
            decoded.value1= readInt16LE(bytes.slice(i, i + 2)) / 10;
            decoded.temperature = readInt16LE(bytes.slice(i, i + 2)) / 10;
            i += 2;

        }

        // HUMIDITY

        else if (channel_id === 0x04 && channel_type === 0x68) {

                  decoded.value2 = bytes[i] / 2;
                  decoded.humidity= bytes[i] / 2;
                  decoded.state1 = "Off";
                  decoded.state2 = "Closed";
            i += 1;

        }

       

        else {

            break;

        }

    }

    return decoded;

}



/* ******************************************
 * bytes to number
 ********************************************/

function readUInt16LE(bytes) {

    var value = (bytes[1] << 8) + bytes[0];

    return value & 0xffff;

}



function readInt16LE(bytes) {

    var ref = readUInt16LE(bytes);

    return ref > 0x7fff ? ref - 0x10000 : ref;

}

Then I made a viritual sensor with temperature and humidity
After that made a flow there i used in “when” section “Uplink message from TTN end device ID” with the name of my device. and in the “then” section “set a virtual sensor value” “measure_temperature” and the tag #value1 and then again “set a virtual sensor value” with “measure_humidity” and the tag #value2.

Then it all worked!

1 Like

Thank you @Peter_Johansson ,

That worked like a charm!

(After I figured out I needed to include the “eui-“ prefix in my device ID AND use the manually keyed “measure-temperature” and “measure-humidity” variables to store the data in, for it to show in my virtual sensor). :rofl:

Thank you for your help!! :+1::handshake:

1 Like

Hello Owen, @Leo838 ,

I am struggling with the different custom Java payload formatters needed for each sensor type though:

The TTN available defaults formatters and the code provided by the manufacturers (e.g GitHub - Milesight-IoT/SensorDecoders) do not trigger the webhook to Homey: only @Peter_Johansson ‘s decoder (that I used for my Milesight EM300-TH sensor) and a self-modified js I created for the Milesight WS101 button did.

That means (I believe):

  • everyone has to find/write different custom Java decoders to work with the homey TTN app…
  • everyone is limited to two states and two values
  • all 4 variables need to have a value before triggering the Homey webhook

It works great for my first two sensors, but was less intuitive than I had hoped …

Its been a long time since I looked at this, unfortunately life got in the way…

When I was developing the app the original aim was to enable custom states/ measurement on each sensor. However it was far from trivial when I was looking at it, perhaps things have changed…

I went with two states & two measurements to give lots of freedom.

Using the Java decoder in the TTN allows the minimum data to be transmitted via LORAWAN (a requirement) but lots of capability to tailor for each application. Its not intuitive however as you say.

But it does work (very well!)
Thank you for your reply and efforts!

Helium network?

@Peter_Johansson @Leo838
I just added a Dragino LDS02 and webhook setup with Homey, but how do i get messages through to Homey? Are there any tutorials for this?

In my ttn application, I recieve plenty of uplinks from my device, but still no triggers in Homey.

Even with the trigger for any uplink from ttn.

Edit:
I also faound a webhook error in the ttn application, but i don’t understand it.

“Fail to send webhook”

{
  "name": "as.webhook.fail",
  "time": "2022-12-03T14:50:26.968852806Z",
  "identifiers": [
    {
      "device_ids": {
        "device_id": "postkasse-magnet-sensor",
        "application_ids": {
          "application_id": "postkasse"
        },
        "dev_eui": "A84041C4B185876A",
        "join_eui": "A840410000000107",
        "dev_addr": "260B4BEB"
      }
    }
  ],
  "data": {
    "@type": "type.googleapis.com/ttn.lorawan.v3.ErrorDetails",
    "namespace": "pkg/applicationserver/io/web",
    "name": "request",
    "message_format": "request",
    "correlation_id": "374f30fdaece48ea9543c8b7718d1655",
    "code": 14,
    "details": [
      {
        "@type": "type.googleapis.com/google.protobuf.Struct",
        "value": {
          "body": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot POST /webhook/60df8366132fac0be2bb85eb/postkasse</pre>\n</body>\n</html>\n",
          "status_code": 404,
          "url": "https://webhooks.athom.com/webhook/60df8366132fac0be2bb85eb/postkasse",
          "webhook_id": "postkasse-webhook-homey"
        }
      }
    ]
  },
  "correlation_ids": [
    "as:up:01GKC7F5R9HFK3DX80WVGV265Y",
    "gs:conn:01GKC794VJGWKNKG2W3N70E5WC",
    "gs:up:host:01GKC794VQACFPRRP8NSZPH59S",
    "gs:uplink:01GKC7F5HSC9PTGDY2T2YXC6GT",
    "ns:uplink:01GKC7F5HTP5Z7K08J0SZ4J1VR",
    "rpc:/ttn.lorawan.v3.GsNs/HandleUplink:01GKC7F5HTV6714J2D9TKPZ3B3",
    "rpc:/ttn.lorawan.v3.NsAs/HandleUplink:01GKC7F5R87WF812GJPAYK2713"
  ],
  "origin": "ip-10-100-12-100.eu-west-1.compute.internal",
  "context": {
    "tenant-id": "CgN0dG4="
  },
  "visibility": {
    "rights": [
      "RIGHT_APPLICATION_TRAFFIC_READ"
    ]
  },
  "unique_id": "01GKC7F5RRA0CP8YWG1MV4KNWB"
}```

@MacMillan Have you followed this guide? GitHub - OOHehir/connector.ttn: Homey app to connect to The Things Stack that @leo838 wrote?

The problem, as @Leo838 states, is time to program :slight_smile: .
I think it would be doable to create an app that supports adding devices using the standard payload decoder.
Maybe (if there is time besides working and making music) i’ll dive into it. I have done it in the past for SureSense, if I can find that code it will probably not be too much work.

1 Like