cyberjunky / RTL-SDR-P2000Receiver-HA

Receive P2000 messages using RTL-SDR stick and post them to Home Assistant
MIT License
23 stars 11 forks source link

multiple HA instances #42

Open spiralshapeturtle opened 1 year ago

spiralshapeturtle commented 1 year ago

Hi team

@royvandongen @cyberjunky @bduijnhouwer @Dinges28 My colleagues and I running HASSIO in a VM, there fore we need a separate PI to run the great RTL-SDR P2000 decoder. It seems a bit overkill if everyone is running a separate Pi for decoding.

Could we request a feature request to add multiple HA instances to post messages to, from one Pi as source? Is it as simple to duplicate home-assistent to home-assistant2?

Thanks for your time.

 self.use_hass2 = self.config.getboolean("home-assistant2", "enabled")
 self.baseurl2 = self.config.get("home-assistant2", "baseurl")
 self.token2 = self.config.get("home-assistant2", "token")

         if self.use_hass2:
                try:
                    self.logger.debug(
                        f"Posting to Home Assistant - {self.sensorname}"
                    )
                    headers = {
                        "Authorization": "Bearer " + self.token,
                        "content-type": "application/json",
                    }

                    response = requests.post(
                        self.baseurl + "/api/states/sensor." + self.sensorname,
                        headers=headers,
                        data=json.dumps(
                            data,
                            default=lambda o: o.__dict__,
                            sort_keys=True,
                            indent=4,
                        ),
royvandongen commented 1 year ago

Hi @rodeho, For the short term it would definatly be possible to multiply the parts of the code where HASS is mentioned (dont forget adding additional config in config.ini). However in order to add this function parts of the code should be rewritten to interpret the HASS servers as an array, We could possibly break backwards compatibility with this. @cyberjunky should decide wether this functionality should be added.

Dinges28 commented 1 year ago

Maybe a simpler solution.

Write to an MQTT broker and let the different hassio read the sensors they want/need.

spiralshapeturtle commented 1 year ago

Maybe a simpler solution.

Write to an MQTT broker and let the different hassio read the sensors they want/need.

That could be a solution, let's dig into that.

spiralshapeturtle commented 1 year ago

Maybe a simpler solution.

Write to an MQTT broker and let the different hassio read the sensors they want/need.

@jan-dewit and I got it rolling, working fine. Maybe @cyberjunky can copy this to the readme.md?

The HA mosquitto is unable to run 2 instances in parallel, you need to adopt the remote feed into your current mosquitto

Step 0: add a new user to the HA instance where the RTL-SDR Pi is located, a normal HA user can read the MQTT feed. Below the test user the RTL-SDR HA instance = cybersecurity

Step 1: In the mosquitto config you add this:

image

Step 2 In the folder where mosquitto reads the config (default: \share\mosquitto) you add a new file. cloudmqtt.conf in this file you add the remote broker.

connection cloudmqtt
address web.broker.net:1883
remote_username cybersecurity
remote_password cybersecurity
clientid cybersecurity
try_private false
start_type automatic
topic # in

Step 3 in the configuration.yaml

sensor:
  - platform: mqtt
    name: "p2000-test"
    unique_id: "p2000-test"
    state_topic: "p2000/sensor/p2000_<your topic>"
    value_template: "{{ value_json.state }}"
    json_attributes_topic: "p2000/sensor/p2000_<your topic>"
    json_attributes_template: >
      { "time received": "{{value_json.attributes['time received']}}",
        "group id": "{{value_json.attributes['group id']}}",
        "receivers": "{{value_json.attributes.receivers}}",
        "capcodes": "{{value_json.attributes.capcodes}}",
        "priority": "{{value_json.attributes.priority}}",
        "disciplines": "{{value_json.attributes.disciplines}}",
        "raw message": "{{value_json.attributes['raw message']}}",
        "region": "{{value_json.attributes.region}}",
        "location": "{{value_json.attributes.location}}",
        "postal code": "{{value_json.attributes['postal code']}}",
        "city": "{{value_json.attributes.city}}",
        "address": "{{value_json.attributes.address}}",
        "street": "{{value_json.attributes.street}}",
        "remarks": "{{value_json.attributes.remarks}}",
        "longitude": "{{value_json.attributes.longitude}}",
        "latitude": "{{value_json.attributes.latitude}}",
        "opencage": "{{value_json.attributes.opencage}}",
        "mapurl": "{{value_json.attributes.mapurl}}",
        "distance": "{{value_json.attributes.distance}}",
        "friendly_name": "{{value_json.attributes.friendly_name}}" }

Step 4:

Checks if it works:

image

Dinges28 commented 1 year ago

@rodeho Great to hear you have it working... Out of curiosity I'm not really getting your solution :-S

You have a location with the sdr receiver, there you run a local mqtt-broker, than you have home assistant (local) and that pushes the mqtt to a cloud broker? Do I get it right here?

spiralshapeturtle commented 1 year ago

@rodeho Great to hear you have it working... Out of curiosity I'm not really getting your solution :-S

You have a location with the sdr receiver, there you run a local mqtt-broker, than you have home assistant (local) and that pushes the mqtt to a cloud broker? Do I get it right here?

We both using HA in a VM, and at my location there is a Pi with the RTL-SDR dongle. The Pi posts to my MQTT data stream. The big challenge is to get a cloud MQTT stream joined within HA, it mainly focussed on local/home streams get it pushed directly from devices. There for my colleague needs to add the cloudmqtt config to get his MQTT broker filed up with my p2000 MQTT messages. Hey joins with a user account on my MQTT broker, defined in the cloudmqtt config.

The other thing we went into, is that he also received my DSMR (meterstanden). To overcome that issue I have implemented MQTT ACL's on the MQTT sender side.

Pi with RTLSDR-> pushes to my local HA MQTT broker ->(internet)<-collegue his local MQTT broker joins my MQTT broker to subscribe to p2000

spiralshapeturtle commented 1 year ago

@Dinges28 one question I'm also experimenting with pagermon a website for pager messages running locally. Do you know if its possible to start the p2000.py with an extra pipe | to node reader.js ?

p2000.py -> rtl_fm -f 169.65M -M fm -s 22050 | multimon-ng -a FLEX -t raw -

pagermon -> rtl_fm -f 169.65M -M fm -s 22050 | multimon-ng -a FLEX -t raw /dev/stdin | node reader.js

Could these to be combined and processing the same data?

Dinges28 commented 1 year ago

I don't know... but maybe you can do it just like ha & mqtt, an extra posting method to node.js?