[SOLVED] Charting a transformed value (D1 mini A0)

Hi, I have a D1 mini that controls my change over from the Utility to the Inverter in the event of a power outage.
The actual change over controls works as intended but i also have the battery voltage on the A0 pin of the D1. The raw input is 0-1024

Items:
String BatteryVDC “Battery Voltage [MAP(Batteryvoltage.map):%s]” (Backup,BackUpLights) {channel=“mqtt:topic:0e16f822:SENSOR”}

The Json transformation is done in the MQTT2.4 binding in paperUI and then i transform the value to a usable number using a Map transformation.

image

But now i would like to chart this transformed value but the chart is showing the input to the string instead of the output.

image

How would i change the transformed string to input into another “dummy” string that i could then chart as a usable value?

Apologies if this is trivial, iv’e tried a few things but i couldn’t get it to work.

Junaid

Try creating the dummy item as a Number, rather than a string, item and use it for the chart.

Would you mind helping me write the rule to post the update from the string to the number?
I think i tried it but could have been a syntax error on my part.

Rough attempt from cell phone.:upside_down_face: Give it a try and post any errors if not working.

rule "Chart"
when
    Item BatteryVCD received update
then
    DummyBattery.postUpdate(BatteryVCD)
end

Another attempt if the first doesn’t work:

rule "Chart"
when
    Item BatteryVCD changed
then
    var battery = BatteryVCD.state as Number
    DummyBattery.postUpdate(battery)
end

Also, don’t forget to craete the Proxy (dummy) item DummyBattery or whatever name you want.

Doesn’t such ommit the needed transformation?

After a second thoughts,:crazy_face: yep your correct.

Sorry, was away for the weekend.
So i tried a few things again;

  • I changed the transformation map to a dimensionless number.

  • I added the rule:
    when
    Item BatteryVDC received update
    then
    BatteryVDC_Chart.postUpdate(BatteryVDC)
    end

but i got this error

Then i changed the rule to just send a broadcast notification when the item is updated and for sure my phone lit up.

So i know

  1. The rule fires on the update of the string (BatteryVDC)

  2. The Item BatteryVDC_Chart is defined correctly

The problem is with

BatteryVDC_Chart.postUpdate(BatteryVDC)

Any help would be appreciated.

Presumably it is the .state of BatteryVDC you are interested in?

@rossko57
Yes it is but the state is transformed through a JSON path in the MQTT2 binding and then mapped with a MAPtransformation.
So the input of that string is 0-1024 but the transformed output is 0-14.99 (Volts DC)

I found another post also trying to change a string to a number i wrote a new rule

var Number conversion
var String get_voltage_register
rule “conversion”
when
Item BatteryVDC changed
then
get_voltage_register = BatteryVDC.state.toString();
conversion = Integer.valueOf(get_voltage_register);
BatteryVDC_Chart.postUpdate(conversion)
end

No errors this time but i still get the input to the string, not the output of the string
image

BatteryVDC_Chart is what I guess you are showing us, it has a value of 5.00 V
You were expecting something else?

I can see a complication, in that you chose to make BatteryVDC_Chart as a Number:ElectricPotential type, rhat than just a Number.
That means you really ought to update it specifying the unit of measurement, otherwise it has to guess - V, mV, kV?

The postUpdate should accept a string for your Number, with UoM, try
BatteryVDC_Chart.postUpdate( BatteryVDC.state.toString + " | V")

So i found a way: Essentially i changed the the place that the transformation is done from the items file to a rule.

items:

String BatteryVDC “Battery Voltage_Register value” {channel=“mqtt:topic:0e16f822:SENSOR” }
Number:ElectricPotential BatteryVDC_Chart “Battery Voltage [%.1f V]” (Backup)

rule:

rule “conversion”

when
Item BatteryVDC changed
then
val trans = transform(“MAP”, “Batteryvoltage.map”, BatteryVDC.state.toString);
BatteryVDC_Chart.postUpdate(trans)
end

And the chart now displays “BatterVDC_Chart” which is the transformed value

image

Now i just need to get the dynamic icon working.

Thank you for taking the time to help my guys, much appreciated.

1 Like