# Geiger value to store in a number variable?

**URL:** <https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810>\
**Category:** Flows\
**Tags:** advancedflow\
**Created:** [November 29, 2022, 9:03am UTC](https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810 "2022-11-29T09:03:29Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_Mithouard](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/nicolas_mithouard/32/35806_2.png) [@Nicolas\_Mithouard](https://community.homey.app/u/Nicolas_Mithouard)\
**Post date:** [November 29, 2022, 9:03am UTC](https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810/1 "2022-11-29T09:03:29Z")

</div>

Hi everyone  
I have a Geiger counter and I’d like to get the CPM value stored in a number variable. I spent 3 days looking for solution but my compétences are too low ….😭😭😭

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/7/b7927a9e5da8111f8e7d29615695a49ecd7d1bf6.jpeg)

In red is the value I want to get  
I use advanced flow to have a text variable with the result … but from that I don’t know how to extract only the value after CPM

Can someone help me ?

Thanks

Nicolas

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/7/57ba17707d7fb7bfac7d1b2fe9842da025f7c1c0.jpeg)  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/5/d514b55500063f3b443934f76a7d7da6a4de41a6.jpeg)

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [November 29, 2022, 9:29am UTC](https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810/2 "2022-11-29T09:29:40Z")

</div>

Hi,  
the API returns not a JSON result, but a HTML page instead.  
Is there a API documentation? Perhaps you can add an url parameter to get the JSON object only?

---

<div class="post-metadata">

**Author:** ![Nicolas\_Mithouard](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/nicolas_mithouard/32/35806_2.png) [@Nicolas\_Mithouard](https://community.homey.app/u/Nicolas_Mithouard)\
**Post date:** [November 29, 2022, 10:32am UTC](https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810/4 "2022-11-29T10:32:28Z")

</div>

In fact, my Geiger counter send values to gmcmap site and I can get the last value dowloaded back from [gmcmap.com](http://gmcmap.com)  
As there’s no api … could it be possible to work on the text variable I named « réponse GMCMAP » to extract the value after CPM and transform in value variable …  
Like in excel file … but I don’t know how to do that …

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/7/a/7a6c82bf15439e7758171314b6586e899c75aa59.jpeg)

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [November 29, 2022, 11:06am UTC](https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810/5 "2022-11-29T11:06:33Z")

</div>

You can’t extract JSON elements if the response is HTML:

 ![grafik](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/7/f7d5ae20a984cddcea0ef4bb2eec52368547d4ce.jpeg)

You need an url to read only the JSON data. This should be documented by [gmcmap.com](http://gmcmap.com)

---

<div class="post-metadata">

**Author:** ![Marcel\_Ubels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/marcel_ubels/32/18860_2.png) [@Marcel\_Ubels](https://community.homey.app/u/Marcel_Ubels)\
**Post date:** [November 29, 2022, 2:44pm UTC](https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810/6 "2022-11-29T14:44:16Z")

</div>

When I try fetch method in homeyscript;

```auto
var test = await fetch('http://gmcmap.com/historyData-plain.asp?Param_ID=44549586449&timezone=1');
console.log(test)

```

This is the response. Is there some way to extract this. The last part of the response seems something like json or array with objects

```auto
Response {
  size: 0,
  timeout: 0,
  [Symbol(Body internals)]: {
    body: Gunzip {
      _writeState: [Uint32Array],
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      bytesWritten: 0,
      _handle: [Zlib],
      _outBuffer: <Buffer 20 0d 0a 0d 0a 0d 0a 3c 21 44 4f 43 54 59 50 45 20 48 54 4d 4c 3e 0d 0a 0d 0a 3c 68 74 6d 6c 3e 0d 0a 20 20 3c 68 65 61 64 3e 0d 0a 20 20 20 3c 6d 65 ... 16334 more bytes>,
      _outOffset: 0,
      _chunkSize: 16384,
      _defaultFlushFlag: 2,
      _finishFlushFlag: 2,
      _defaultFullFlushFlag: 3,
      _info: undefined,
      _maxOutputLength: 1073741823,
      _level: -1,
      _strategy: 0,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: null,
      [Symbol(kError)]: null
    },
    disturbed: false,
    error: null
  },
  [Symbol(Response internals)]: {
    url: 'http://gmcmap.com/historyData-plain.asp?Param_ID=44549586449&timezone=1',
    status: 200,
    statusText: 'OK',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: 0
  }
}

```

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [November 29, 2022, 2:59pm UTC](https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810/7 "2022-11-29T14:59:56Z")

</div>

`fetch` only returns a response object, if you want to extract the response body use something like this:

```auto
const html = await test.text();

```

And then hack out the JSON:

```auto
const data = JSON.parse( html.match(/\{.+?\}/s)[0]) );

```

---

<div class="post-metadata">

**Author:** ![Nicolas\_Mithouard](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/nicolas_mithouard/32/35806_2.png) [@Nicolas\_Mithouard](https://community.homey.app/u/Nicolas_Mithouard)\
**Post date:** [November 29, 2022, 3:43pm UTC](https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810/8 "2022-11-29T15:43:59Z")

</div>

> [@Marcel\_Ubels](#):
>
> `test)`

Thanks both of you …  
As i’m novice in script …robertklep could you describe a bit more ? I don’t even understand what to write in homeyscript 😭😭😭

I found a solution with this but it’s not clean enough as i look for text and convert … I would prefer do in your way guys …

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/2/a231214edf89cfca87447bc896cdee8c352cae4b.jpeg)

---

<div class="post-metadata">

**Author:** ![Nicolas\_Mithouard](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/nicolas_mithouard/32/35806_2.png) [@Nicolas\_Mithouard](https://community.homey.app/u/Nicolas_Mithouard)\
**Post date:** [November 29, 2022, 3:48pm UTC](https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810/9 "2022-11-29T15:48:03Z")

</div>

Lost lost lost …. Perhaps too old. 😂😂😂

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/9/b9636cac18dca8082f6c2fb2d06dec9f13ae086f.jpeg)

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [November 29, 2022, 3:49pm UTC](https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810/10 "2022-11-29T15:49:39Z")

</div>

> [@robertklep](#):
>
> `const data = JSON.parse( html.match(/\{.+?\}/s)[0]) );`

Ah one parentheses too many:

```auto
const data = JSON.parse( html.match(/\{.+?\}/s)[0] );

```

---

<div class="post-metadata">

**Author:** ![Nicolas\_Mithouard](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/nicolas_mithouard/32/35806_2.png) [@Nicolas\_Mithouard](https://community.homey.app/u/Nicolas_Mithouard)\
**Post date:** [November 29, 2022, 3:54pm UTC](https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810/11 "2022-11-29T15:54:54Z")

</div>

thanks … i will work on that and give you feedback

---

<div class="post-metadata">

**Author:** ![Nicolas\_Mithouard](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/nicolas_mithouard/32/35806_2.png) [@Nicolas\_Mithouard](https://community.homey.app/u/Nicolas_Mithouard)\
**Post date:** [November 29, 2022, 4:06pm UTC](https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810/12 "2022-11-29T16:06:21Z")

</div>

![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/6/5/650e21484c0e60fcce36bf7a622e28cdd209eb3d.jpeg)  
 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/0/c08134920c0a2a6a6a14a0a097fdade1aac2383e.jpeg)

Lol … I’m not good at all

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [November 29, 2022, 5:06pm UTC](https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810/13 "2022-11-29T17:06:48Z")

</div>

End the script with this:

```auto
return data.CPM;

```

---

<div class="post-metadata">

**Author:** ![Nicolas\_Mithouard](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/nicolas_mithouard/32/35806_2.png) [@Nicolas\_Mithouard](https://community.homey.app/u/Nicolas_Mithouard)\
**Post date:** [November 29, 2022, 6:20pm UTC](https://community.homey.app/t/geiger-value-to-store-in-a-number-variable/72810/14 "2022-11-29T18:20:20Z")

</div>

works perfectly … thank you very much for that
