JTK – Notes and Ramblings Things we have found …

1/25/2023

Openhab transforms and MQTT JSON data

Filed under: General — taing @ 5:57 pm

In a previous post discussing Openhab JSONPATH transformations there was an issue when the same MQTT topic is used for several different messages. In the case of the LaCrosse Weather sensor one message contains temperature and humidity and the other message contains wind speed and direction.

The solution is to chain transformations. First use a REGEX to filter and then use the JSONPATH to extract the value. This is discussed in the Openhab forums. For the weather sensor the wind direction transformation looks like:

REGEX:(.*wind_dir_deg.*)?JSONPATH:$.wind_dir_deg

Pay special attention to the union symbol ?. It is really what makes the magic. As explained in the forum post the parenthesis in the REGEX pass the entire message on to the next transform if there is a match.

Mighty Mule and LaCrosse Update

Filed under: General,Home Automation,RTL-SDR — taing @ 4:45 pm

It turns out there is another Mighty Mule Driveway Alarm somewhere in the neighborhood so the config from our previous article needed to be updated. The other signal is weak but it triggers frequently and requires the config to be a bit more sophisticated. The first step was to update the rtl_433.conf file to send the MQTT messages as a JSON packet:

output json
output mqtt://broker_ip_address,events=rtl_433/garage[/model]

The result looks something like(after I prettied it up with a bit of formatting):

rtl_433/garage/MightyMule-FM231 {
	"time":"2023-01-24 18:37:05.994411",
	"model":"MightyMule-FM231",
	"count":1,
	"num_rows":1,
	"len":9,
	"data":"ff8",
	"battery_ok":"0",
	"id":15,
	"motion":"true",
	"mod":"ASK",
	"freq":433.89011,
	"rssi":-9.5411,
	"snr":12.69084,
	"noise":-22.2319
}

It’s all the same data but in one message. The Openhab config gets changed to have a String Channel for the MQTT JSON packet, an String Item linked to this and two additional String Items a new rule will manipulate. The rule checks the if the id matches our unit and then updates the appropriate items. The id is set on the transmitter and receiver with the dip switches. The rule is very basic but it does the job:

rule "Driveway Alarm" when
  Item Mighty_Mule_JSON received update
then
  var jsonval = Mighty_Mule_JSON.state.toString
  var id = transform("JSONPATH", "$.id", jsonval)
  var time = transform("JSONPATH", "$.time", jsonval)
  if (id == "5") {
    MightyMule_Driveway_Motion.postUpdate("ON")
    MightyMule_Driveway_Motion_Change.postUpdate(time)
  }
end

Changing the rtl_433 MQTT output to be JSON also required updating the channels for the LaCrosse Weather station. Previously the Generic MQTT Thing had channels for individual MQTT messages for temperature, humidity, wind speed and wind direction. Now the JSON messages from the weather station require the channel to have a JSONPATH transformation. The weather station will send two messages, one with temperature and humidity and one with wind speed and direction:

rtl_433/garage/LaCrosse-TX141W {
	"time":"2023-01-24 18:09:36.626950",
	"protocol":73,
	"model":"LaCrosse-TX141W",
	"id":149742,
	"channel":0,
	"battery_ok":1,
	"temperature_C":-0.8,
	"humidity":74,
	"test":0,
	"mic":"CRC",
	"mod":"ASK",
	"freq":433.87334,
	"rssi":-0.135693,
	"snr":22.09624,
	"noise":-22.2319
}

rtl_433/garage/LaCrosse-TX141W {
	"time":"2023-01-24 18:09:36.626950",
	"protocol":73,
	"model":"LaCrosse-TX141W",
	"id":149742,
	"channel":0,
	"battery_ok":1,
	"wind_avg_km_h":4.5,
	"wind_dir_deg":139,
	"test":0,
	"mic":"CRC",
	"mod":"ASK",
	"freq":433.87334,
	"rssi":-0.135693,
	"snr":22.09624,
	"noise":-22.2319
}

A MQTT channel with a topic of rtl_433/garage/LaCrosse-TX141W will receive both messages. The trick is in the JSONPATH transformation. To extract temperature, for example, use JSONPATH:$.temperature_C. This means there are four channels with the same MQTT topic and different JSONPATH transformations. The log file will get warnings that you can’t extract wind speed from the temp/humidity message or temp/humidity from the wind message.

NOTE: Our LaCrosse S81120-INT includes the LaCrosse TX145WSDTH which sends messages as LaCrosse-TX141W.

?

1/23/2023

Mighty Mule Driveway Alarm

Filed under: General — taing @ 9:07 am

Some time ago a Mighty Mule FM231 Driveway Alarm was installed. This is an electromagnetic inductive sensor with a transmitter and indoor receiver. Various ways of linking this to Openhab were considered. Since an sdr is already setup and configured to handle the LaCrosse weather station, the best solution seems to be to use a rtl_433 decoder to generate messages to the MQTT broker.

Once you have rtl_433 setup with your sdr, the next step is to add the decoder to your rtl_433.conf file:

decoder {
    name=MightyMule-FM231,
    modulation=OOK_PWM,
    short=650,
    long=1200,
    sync=3800,
    reset=1100,
    rows=1,
    bits=9,
    get=@4:{1}:battery_ok:[0:1 1:0],
    get=@5:{4}:id,
    get=@0:{1}:motion:[0:true 1:true],
    unique
}

The next step is to assure you have rtl_433 setup to send MQTT messages to your broker:

output mqtt://broker_ip_address,devices=rtl_433/garage[/model]

For me this results in messages that look something like:

rtl_433/garage/MightyMule-FM231/time 2023-01-22 11:39:48.795951
rtl_433/garage/MightyMule-FM231/count 1
rtl_433/garage/MightyMule-FM231/num_rows 1
rtl_433/garage/MightyMule-FM231/len 9
rtl_433/garage/MightyMule-FM231/data 728
rtl_433/garage/MightyMule-FM231/battery_ok 1
rtl_433/garage/MightyMule-FM231/id 5
rtl_433/garage/MightyMule-FM231/motion true
rtl_433/garage/MightyMule-FM231/mod ASK
rtl_433/garage/MightyMule-FM231/freq 433.98368
rtl_433/garage/MightyMule-FM231/rssi -0.124222
rtl_433/garage/MightyMule-FM231/snr 25.3924
rtl_433/garage/MightyMule-FM231/noise -25.5166

With this all setup, a Openhab Generic MQTT Thing was created with a Channel for the MQTT topic “rtl_433/garage/MightyMule-FM231/motion”. Two items were created, one for the channel itself and a second linking to the channel with a “Timestamp on Change” profile. Metadata for an Expiration Timer was added to the motion item to reset(the unit never sends motion false).

1/13/2023

Yoda Lights Up

Filed under: Arduino,General — taing @ 4:25 pm

As a follow-up to Yoda Speaks, we now have Yoda Lights Up. We have added a Sparkfun WS2812 Thru-Hole RGB LED to Yoda’s hand. There is a helpful Sparkfun WS2812 Hook-up guide. It allows for easy setup with the Sparkfun Papa Soundie we are using for the sound playback.

The LED is connected to Vcc/+5vdc, GND and Pin 10. We chose to use the FastLED library for our setup. There is a wiki online to answer many of your questions. As for code, our example is pretty simple:

#include <FastLED.h>

#define DATA_PIN    10
#define NUM_LEDS    1
#define LED_TYPE    WS2812
#define COLOR_ORDER RGB

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
}

void loop() {
  leds[0].setRGB(0,255,0);
// or
  leds = CRGB::Green;
  FastLED.show(); 
  delay(30);
}

Sparkfun points to some example code and the Adafruit NeoPixel library. Additional it is also recommended to add a series resistor(220 – 470 ?) on the data line and a filter capacitor(100µF – 1000µF) across the power lines if using more than a pixel of two. If you are using a large number of pixels there is a nice article on Large Power Loads and Daisy Chained LED Strips.

Powered by WordPress