API help needed with Geiger Counter integration

I just got my GQ GMC320 Geiger Counter with Wifi. It logs data and it also can send the data directly to the website of GMC where it stores it (based on an interval you set).

However you can modify some of the parameters (in the device) so it actually sends the data to another destination. You can set two fields: A website ‘server’ (example ‘www.gmcmap.com’) and a website ‘URL’ (example ‘log2.asp’).

Seemingly it then creates “http://www.GMCmap.com/log2.asp?AID=UserAccountID&GID=GeigerCounterID &CPM=nCPM&ACPM=nACPM&uSV=nuSV”

I would love to get this data directly into HASS but I’m limited to the two fields available in the device I can use to customise the URL.

Any suggestion I could get this in HASS directly or if needed via a de-tour?

I recommend setting up a “man-in-the-middle” file on some webserver you have access to (preferably the raspberry pi hass is running on, google helps with setting up your own webserver). Just set up a webserver and put some file (like mim.html) in the web-base.

Point your geiger counter to that address (like http://server-address/mim.html). Then try around to find out how and which data is redirected to that webpage (have a php-script writing it in a file oder some other method of logging), format the data and forward it to your home assistant via the RESTful API.

I would love to help you as this sound fiddely and requires some knowledge of JS/php but with some internet I’m sure you’ll make it!

1 Like

Did you manage to make it work? You can go to my site for a complete manual:
https://www.connectix.nl/connecting-a-geiger-counter-to-home-assistant/

Thanks. Never really got it connected. You project looks cool. However not sure how I can make it work with my GQ. I was hoping I could use the build in ability of the GQ to post the data to something that is available to HASS. I also need it connected via wifi as the location near to my hass server was giving some issues now and then with the geiger counter (for still unknown reasons)

EDIT: I just found some software to log it on a PC. That could work (although not ideal). The issue is it stores the data on the PC (I have one running 24/7). I would then need to find a way to read that data from the PC into HASS…

Hey, if you are already pushing your data to www.gmcmap.com, you can use following sensors:

sensor:
  - platform: command_line
    name: "Geiger meter (CPM)"
    scan_interval: 30
    unit_of_measurement: CPM
    value_template: "{{ value_json.CPM }}"
    command: "curl -s 'http://www.gmcmap.com/historyData-plain.asp?Param_ID=SENSOR_ID' | tr -d $'\r' | tr -d '[:space:]' | awk -v FS='(table-hover\">|</table)' '{print $2}' | jq"
  - platform: command_line
    name: "Geiger meter (ACPM)"
    scan_interval: 30
    unit_of_measurement: ACPM
    value_template: "{{ value_json.ACPM }}"
    command: "curl -s 'http://www.gmcmap.com/historyData-plain.asp?Param_ID=SENSOR_ID' | tr -d $'\r' | tr -d '[:space:]' | awk -v FS='(table-hover\">|</table)' '{print $2}' | jq"
  - platform: command_line
    name: "Geiger meter (uSv)"
    scan_interval: 30
    unit_of_measurement: uSv
    value_template: "{{ value_json.uSv }}"
    command: "curl -s 'http://www.gmcmap.com/historyData-plain.asp?Param_ID=SENSOR_ID' | tr -d $'\r' | tr -d '[:space:]' | awk -v FS='(table-hover\">|</table)' '{print $2}' | jq"
  - platform: command_line
    name: "Geiger meter (time)"
    scan_interval: 30
    unit_of_measurement: time
    value_template: "{{ strptime(value_json.time, '%Y-%m-%d%H:%M:%S') }}"
    command: "curl -s 'http://www.gmcmap.com/historyData-plain.asp?Param_ID=SENSOR_ID' | tr -d $'\r' | tr -d '[:space:]' | awk -v FS='(table-hover\">|</table)' '{print $2}' | jq"

Just replace SENSOR_ID with your actual sensor ID. I have also found below API endpoints that could be used to play arround with:

  • http://www.gmcmap.com/gmc-plain-data.asp?Param_ID=SENSOR_ID
  • http://www.gmcmap.com/historyData-plain.asp?Param_ID=SENSOR_ID
  • http://www.gmcmap.com/historyData.asp?Param_ID=SENSOR_ID
4 Likes

Unfortunately this was a good time to implement this! Works flawlessly. Thanks

gmcmap seems unavailable, this happens more? i would like to fetch just a value from around my neighbourhood, would that be possible without having the device?

for the device, it seems there is a project on serial integration: GitHub - gi1mic/gmc320: CQ GMC3xx Radiation Monitor addon for homeassistant

For sensor_id, you can find a device nearby on that map and copy value for sensor_id from the map. Just move the mouse cursor over “History Button” and you will find the id in the link that button points to

Cool, I’ll have look at that

They’ve recently gone through some changes and when it came back up my script stopped working. I’m not familiar with parsing JSON and I’m hoping someone knows what the issue might be.

Current YAML looks like:

  - platform: command_line
    name: "NR Geiger meter (uSv)"
    unique_id: 'nr_gmc_usv'
    scan_interval: 900
    unit_of_measurement: uSv
    value_template: "{{ value_json.uSv }}"
    command: "curl -s 'https://www.gmcmap.com/historyData-plain.asp?Param_ID=PUTIDHERE' | tr -d $'\r' | tr -d '[:space:]' | awk -v FS='(table-hover\">|</table)' '{print $2}' | jq"

The web site returns:
{"time":"2023-02-07 07:04:36 MST","CPM":"29","ACPM":"28.33","uSv":"0.19"}

But the parsing is only returning state “unknown”.

I’m hoping someone who knows JSON better can shed some light on this.

Edit: Nevermind, I switched to using REST on a 15 min timer.

1 Like

whats your config now then? no longer command_line?

1 Like

I am also very interested in your solution. Would you be so kind and help us out?

This is my current setup and it works so far. I don’t know if this is fully correct I played around and just managed to get the data from the gmcmap :slight_smile:

sensor:
  - platform: rest
    scan_interval: 60
    unit_of_measurement: CPM
    resource: http://www.gmcmap.com/historyData-plain.asp?Param_ID=PUTIDHERE
    unique_id: geiger_meter_cpm_2
    name: Geiger meter (CPM)
    value_template: "{{ value_json.CPM }}"
1 Like

i see not all stations have a history button… cant figure the ID for this one:
image
should i just leave this one and find one with history?

1 Like

Sorry about the late reply, yes, I was using the same rest code as Bodek333 and it started working but has stopped as of late this afternoon. No idea what’s going on with that site but I’m going to shelve this for now.

1 Like

I’ve found the error I was getting with GMCMap. It’s an error with their output, they have an HTML tag suck on the end of their JSON and it’s causing a parse error. I’ve posted about it on their forums so hopefully gets their attention. I’m upset at myself for not seeing it earlier but I was just looking at the output in my browser and missed it.

Currently the link:

https://www.gmcmap.com/historyData-plain.asp?Param_ID=65115959476

gives:

{"time":"2023-02-10 09:12:00 MST","CPM":"16","ACPM":"19.81","uSv":"0.10"}<br>

The HTML line break at the end is not defined by JSON and while it will not show up when viewed in a >web browser, it will cause JSON parsers to break. You can “view page source” to verify that the HTML >line break exists.

Parse error on line 1:
...19.81","uSv":"0.19"}<br>
-----------------------^
Expecting 'EOF', '}', ',', ']', got 'undefined'
2 Likes

For those wanting code that works right now, you can use the following:

sensor:
  - platform: rest
    name: "XYZ Geiger meter (uSv)"
    unique_id: 'xyz_gmc_rest_usv'
    unit_of_measurement: uSv
    scan_interval: 900
    resource: https://www.gmcmap.com/historyData-plain.asp?Param_ID=XXXXXXXXXX
#    value_template: "{{ value_json.uSv }}"
    value_template: "{{ value.split('\"')[15] }}"
3 Likes

I fixed if like this from my end:

sensor:
  - platform: command_line
    name: "Geiger meter (CPM)"
    scan_interval: 30
    unit_of_measurement: CPM
    value_template: "{{ value_json.CPM }}"
    command: "curl -s 'http://www.gmcmap.com/historyData-plain.asp?Param_ID=XXX&timezone=+2' | tr -d $'<br>' | jq"
  - platform: command_line
    name: "Geiger meter (ACPM)"
    scan_interval: 30
    unit_of_measurement: ACPM
    value_template: "{{ value_json.ACPM }}"
    command: "curl -s 'http://www.gmcmap.com/historyData-plain.asp?Param_ID=XXX&timezone=+2' | tr -d $'<br>' | jq"
  - platform: command_line
    name: "Geiger meter (uSv)"
    scan_interval: 30
    unit_of_measurement: uSv
    value_template: "{{ value_json.uSv }}"
    command: "curl -s 'http://www.gmcmap.com/historyData-plain.asp?Param_ID=XXX&timezone=+2' | tr -d $'<br>' | jq"
  - platform: command_line
    name: "Geiger meter (time)"
    scan_interval: 30
    unit_of_measurement: "Time delta"
    value_template: "{{ relative_time(strptime(value_json.time, '%Y-%m-%d%H:%M:%S')) }}"
    command: "curl -s 'http://www.gmcmap.com/historyData-plain.asp?Param_ID=XXX&timezone=+2' | tr -d $'<br>' | jq"

Once they will remove <br>, it should still work

1 Like

They have fixed their code and actually put in fully correct JSON. Working code should now look like this:

  - platform: rest
    name: "XYZ Geiger meter (uSv)"
    unique_id: 'xyz_gmc_rest_usv'
    unit_of_measurement: uSv
    scan_interval: 900
    resource: https://www.gmcmap.com/historyData-plain.asp?Param_ID=XXXXXXXXXXX
    value_template: "{{ value_json.0.uSv }}"

They have also added a feature to allow you to grab an entire array and reference it properly. The link is:

resource: https://www.gmcmap.com/historyData-plain.asp?Param_ID=XXXXXXXXXXX&n=NNN

NNN represents the number of recent entries. It will return a JSON array that can be referenced as:

    value_template: "{{ value_json.0.uSv }}"
    value_template: "{{ value_json.1.uSv }}"
    value_template: "{{ value_json.2.uSv }}"
    value_template: "{{ value_json.3.uSv }}"
    ...
1 Like

Only noticed this now. When I change my code I get an error on the log’s:

Template variable error: list object has no element 0 when rendering '{{ value_json.0.uSv }}'

With:

- platform: rest
  name: "Geiger meter (uSv)"
  unique_id: "geiger_usv"
  unit_of_measurement: uSv
  scan_interval: 900
  resource: https://www.gmcmap.com/historyData-plain.asp?Param_ID=1535xxxxxx
  value_template: "{{ value_json.0.uSv }}"

Is this still working for you?