# How to store output from exec binding as Numbers?

**URL:** <https://community.openhab.org/t/how-to-store-output-from-exec-binding-as-numbers/24556>\
**Category:** Bindings\
**Tags:** exec, openhab2, binding\
**Created:** [March 6, 2017, 10:12pm UTC](https://community.openhab.org/t/how-to-store-output-from-exec-binding-as-numbers/24556 "2017-03-06T22:12:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaronk6](https://community.openhab.org/user_avatar/community.openhab.org/aaronk6/32/71660_2.png) [@aaronk6](https://community.openhab.org/u/aaronk6)\
**Post date:** [March 6, 2017, 10:12pm UTC](https://community.openhab.org/t/how-to-store-output-from-exec-binding-as-numbers/24556/1 "2017-03-06T22:12:00Z")

</div>

I have defined the following `Things`:

```auto
Thing exec:command:apc_status [command="/sbin/apcaccess -u -p STATUS", interval=10, timeout=5, autorun=false]
Thing exec:command:apc_timeleft [command="/sbin/apcaccess -u -p TIMELEFT", interval=10, timeout=5, autorun=false]
Thing exec:command:apc_loadpct [command="/sbin/apcaccess -u -p LOADPCT", interval=10, timeout=5, autorun=false]
Thing exec:command:apc_linev [command="/sbin/apcaccess -u -p LINEV", interval=10, timeout=5, autorun=false]

```

`apc_timeleft`, `apc_loadpct`, and `apc_linev` return numbers and I’d like to assign them to items of type `Number`.

The following does **not** work:

```auto
Number APC_Timeleft { channel="exec:command:apc_timeleft:output" }
Number APC_Loadpct { channel="exec:command:apc_loadpct:output" }
Number APC_Linev { channel="exec:command:apc_linev:output" }

```

I only see values when I define the items as `Strings`.

Do I need to set up rules to do the typecasting? Or is there an easier approach?

---

<div class="post-metadata">

**Author:** ![halloween](https://community.openhab.org/user_avatar/community.openhab.org/halloween/32/7493_2.png) [@halloween](https://community.openhab.org/u/halloween)\
**Post date:** [March 7, 2017, 10:10am UTC](https://community.openhab.org/t/how-to-store-output-from-exec-binding-as-numbers/24556/2 "2017-03-07T10:10:58Z")

</div>

Maybe you can make a string item which gets the exec-Data.

Or you can read out the exec-Data not with an item. You can also make it inside a rule with cron-job.

I make nearly the same with my power-meter. I made tests with all ways of reading out the data. item, thing and rule.

Now i use the thing to do this. But the other ways were working also.

Here is my rule. My power meter sends the data as string to an item.

```php
rule "Alle Stromzähler auslesen - neu"
	when
			Item PowerMeter_new received update // String Item linked to exec:command channel that runs above script
	then
			//logInfo("Powermeter-new", "TEST " + PowerMeter_new)
			var lines = PowerMeter_new.state.toString.split('\n')
			logInfo("Powermeter-new", "alles ok - lines --> " + lines.size('\n'))
			if (lines.size('\n') == 10) {
					val counterStr = lines.get(0).split('#').get(1)
					val supplyStr = lines.get(1).split('#').get(1)
					val consumptionStr = lines.get(4).split('#').get(1)
					val solarcounterStr = lines.get(5).split('#').get(1)
					val solar1Str = lines.get(6).split('#').get(1)
					val solarpowerStr = lines.get(9).split('#').get(1)
					stromzaehler0_bezug.sendCommand(counterStr)
					stromzaehler0_einspeisung.postUpdate(supplyStr)
					stromzaehler0_leistung.postUpdate(consumptionStr)
					stromzaehler1_leistung.postUpdate(solarpowerStr)
					stromzaehler1_leistung1.postUpdate("-" + solarpowerStr)
					stromzaehler1_erzeugung.sendCommand(solarcounterStr)
					stromzaehler1_ungenutzt.postUpdate(solar1Str)
					var hausverbrauch_aktuell = (Double::parseDouble(consumptionStr)) + (Double::parseDouble(solarpowerStr))
					if (hausverbrauch_aktuell < 0) {
							logInfo("Powermeter-new", "Fehler - Verbrauch negativ --> " + hausverbrauch_aktuell + " kW")
							stromzaehler_haus_leistung.postUpdate(0)
					}
					else {
							stromzaehler_haus_leistung.postUpdate(hausverbrauch_aktuell)
					}
			}
			else if ...
...
...
...
end

```

I get a string with 10 lines, so i did some splitting first to get each value. But you only get a single line with one value. So you don´t need the line with " var lines…" the if and the split-command.

---

<div class="post-metadata">

**Author:** ![aaronk6](https://community.openhab.org/user_avatar/community.openhab.org/aaronk6/32/71660_2.png) [@aaronk6](https://community.openhab.org/u/aaronk6)\
**Post date:** [March 7, 2017, 6:11pm UTC](https://community.openhab.org/t/how-to-store-output-from-exec-binding-as-numbers/24556/3 "2017-03-07T18:11:40Z")

</div>

Thanks, that’s helpful!

I’ll use a rule-based approach then. Just wanted to make sure that I don’t miss anything obvious that would have made my life easier 🙂
