It is currently April 8th, 2020, 2:57 am

2 Problems in 1 Code

Get help with installing and using Rainmeter.
Enno
Posts: 5
Joined: December 25th, 2019, 8:36 am

2 Problems in 1 Code

Post by Enno »

Hi to all,

i´m using Rainmeter to show my tesla state.
querying teslafi.com by webparser i get all the needed information.

But 1st the meterTitle will only show %1
And 2nd measureodometerKmh will show Kilometer without leading Zeros. So sometimes it will show Kilometers like: 23.14,5 and should be 23.014,5

Is anyone able to help me?

thanks in advance und many regards
Enno

2019-12-25.09_42_03--D__Users_Lars_Documents_Rainmeter_Skins_Enno_Tesla_Tesla.ini.png

Code: Select all

; Lines starting ; (semicolons) are commented out.
; That is, they do not affect the code and are here for demonstration purposes only.
; ----------------------------------

[Rainmeter]
; This section contains general settings that can be used to change how Rainmeter behaves.
Update=1000
Background=#@#Background.png
; #@# is equal to Rainmeter\Skins\illustro\@Resources
BackgroundMode=3
BackgroundMargins=0,34,0,14

[Metadata]
; Contains basic information of the skin.
Name=Teslafi.com
Author=Enno
Information=Shows the state of a Tesla using teslafi.com
License=Creative Commons BY-NC-SA 3.0
Version=1.0.0

[Variables]
; Variables declared here can be used later on between two # characters (e.g. #MyVariable#).
fontName=Trebuchet MS
textSize=8
colorBar=235,170,0,255
colorText=255,255,255,205


[measureSite]
; This measure returns the overall status of the car
Measure=Plugin
Plugin=WebParser
URL=https://www.teslafi.com/feed.php?token=***TOKEN***
UpdateRate=300
RegExp=(?siU)"display_name":"(.*)",.*"time_to_full_charge":"(.*)",.*"charge_current_request":"(.*)",.*"charger_power":"(.*)",.*"usable_battery_level":"(.*)",.*"est_battery_range":"(.*)",.*"inside_temp":"(.*)",.*"odometer":"(.*)",
;1 = display_name 
;2 = time to full charge
;3 = charge_current_request
;4 = charger_power
;4 = usable battery level
;5 = est_battery_range
;6 = inside temp
;7 = odometer

[measureName]
Measure=Plugin
Plugin=WebParser
URL=[measureSite]
StringIndex=1
Substitute="":"K.I.T.T. is sleeping"

[measureTimeToFullCharge]
Measure=Plugin
Plugin=WebParser
URL=[measureSite]
StringIndex=2

[measurehourToFullCharge]
Measure=Calc
Formula=Trunc(measureTimeToFullCharge)

[measureminuteToFullCharge]
Measure=Calc
Formula=Trunc(Frac(measureTimeToFullCharge)*60)

[measureChargeCurrentRequest]
Measure=Plugin
Plugin=WebParser
URL=[measureSite]
StringIndex=3

[measureChargePower]
Measure=Plugin
Plugin=WebParser
URL=[measureSite]
StringIndex=4

[measureactualSoC]
Measure=Plugin
Plugin=WebParser
URL=[measureSite]
StringIndex=5

[measureestBatteryRange]
Measure=Plugin
Plugin=WebParser
URL=[measureSite]
StringIndex=6

[measureestBatteryRangeKm]
Measure=Calc
Formula=((measureestBatteryRange)*1.60934)

[measureinsideTemp]
Measure=Plugin
Plugin=WebParser
URL=[measureSite]
StringIndex=7

[measureodometer]
;Kilometerstand
Measure=Plugin
Plugin=WebParser
URL=[measureSite]
StringIndex=8

[measureodometerKmt]
;Kilometerstand vor tausendertrennzeichen
Measure=Calc
Formula=Trunc(measureodometer*1.60934 / 1000)

[measureodometerKmh]
;Kilometerstand nach tausendertrennzeichen
Measure=Calc
Formula=Trunc(Frac(measureodometer*1.60934 / 1000)*1000)


[measureodometerKmk]
;Kilometerstand nach 1 Stelle nach Komma
Measure=Calc
Formula=Trunc(Frac(measureodometer*1.60934)*10)

[measureDisplayName]
Measure=measureName
Measure2=measureChargeCurrentRequest
Measure3=measureChargePower
IfCondition=(%3 > 0)
IfTrueAction=[!SetOption meterTitle Text "%1 lädt mit %2A/%3KW"]

; ----------------------------------
; STYLES are used to "centralize" options
; ----------------------------------

[styleTitle]
StringAlign=Center
StringCase=Upper
StringStyle=Bold
StringEffect=Shadow
FontEffectColor=0,0,0,50
FontColor=#colorText#
FontFace=#fontName#
FontSize=10
AntiAlias=1
ClipString=1

[styleLeftText]
StringAlign=Left
; Meters using styleLeftText will be left-aligned.
StringCase=None
StringStyle=Bold
StringEffect=Shadow
FontEffectColor=0,0,0,20
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
AntiAlias=1
ClipString=1

[styleRightText]
StringAlign=Right
StringCase=None
StringStyle=Bold
StringEffect=Shadow
FontEffectColor=0,0,0,20
FontColor=#colorText#
FontFace=#fontName#
FontSize=#textSize#
AntiAlias=1
ClipString=1

[styleBar]
BarColor=#colorBar#
BarOrientation=HORIZONTAL
SolidColor=255,255,255,15

[styleSeperator]
SolidColor=255,255,255,15

; ----------------------------------
; METERS display images, text, bars, etc.
; ----------------------------------

[meterTitle]
Meter=String
MeterStyle=styleTitle
MeasureName=measureDisplayName
; Using MeterStyle=styleTitle will basically "copy" the
; contents of the [styleTitle] section here during runtime.
X=100
Y=12
W=190
H=18
Text=%1

[meterodometerKmLabel]
Meter=String
MeterStyle=styleLeftText
X=10
Y=40
W=190
H=14
Text=Kilometerstand:

[meterodometerKm]
Meter=String
MeterStyle=styleRightText
MeasureName=measureodometerKmt
MeasureName2=measureodometerKmh
MeasureName3=measureodometerKmk
X=200
Y=0r
; r stands for relative. In this case, the Y postition of meterValueCPU is 0 pixels
; below the Y value of the previous meter (i.e it's the same as in meterLabelCPU).
W=190
H=14
Text="%1.%2,%3 km"
; %1 stands for the value of MeasureName (measureIP in this case).

[meterinsideTempLabel]
Meter=String
MeterStyle=styleLeftText
X=10
Y=60
W=190
H=14
Text=Temperatur:

[meterinsideTemp]
Meter=String
MeterStyle=styleRightText
MeasureName=measureinsideTemp
X=200
Y=0r
; r stands for relative. In this case, the Y postition of meterValueCPU is 0 pixels
; below the Y value of the previous meter (i.e it's the same as in meterLabelCPU).
W=190
H=14
Text="%1 °C"
; %1 stands for the value of MeasureName (measureIP in this case).

[meteractualSoCLabel]
Meter=String
MeterStyle=styleLeftText
X=10
Y=80
W=190
H=14
Text=SoC:

[meteractualSoc]
Meter=String
MeterStyle=styleRightText
MeasureName=measureactualSoC
MeasureName2=measureestBatteryRangeKm
X=200
Y=0r
; r stands for relative. In this case, the Y postition of meterValueCPU is 0 pixels
; below the Y value of the previous meter (i.e it's the same as in meterLabelCPU).
W=190
H=14
Text="%1 % = %2 km"
; %1 stands for the value of MeasureName (measureIP in this case).

[meterTimeToFullChargeLabel]
Meter=String
MeterStyle=styleLeftText
X=10
Y=100
W=190
H=14
Text=Zeit bis Voll:

[meterTimeToFullCharge]
Meter=String
MeterStyle=styleRightText
MeasureName=measurehourToFullCharge
MeasureName2=measureminuteToFullCharge
X=200
Y=0r
; r stands for relative. In this case, the Y postition of meterValueCPU is 0 pixels
; below the Y value of the previous meter (i.e it's the same as in meterLabelCPU).
W=190
H=14
Text="%1 h %2 min"
; %1 stands for the value of MeasureName (measureIP in this case).
You do not have the required permissions to view the files attached to this post.
Last edited by balala on December 25th, 2019, 3:10 pm, edited 1 time in total.
Reason: Please use <code> tags, not <quote>, whenever are you posting code snippets. It's the </> button.
mak_kawa
Posts: 564
Joined: December 30th, 2015, 9:47 am

Re: 2 Problems in 1 Code

Post by mak_kawa »

For the 1st. problem.

Code: Select all

[measureDisplayName]
Measure=measureName
Measure2=measureChargeCurrentRequest
Structure of [measureDisplayName] measure is incorrect.
Enno
Posts: 5
Joined: December 25th, 2019, 8:36 am

Re: 2 Problems in 1 Code

Post by Enno »

Hey thanks,

but how can i fixe it?
whats the right block for manipulating strings?
mak_kawa
Posts: 564
Joined: December 30th, 2015, 9:47 am

Re: 2 Problems in 1 Code

Post by mak_kawa »

I am not fully sure what you intend...and did not try actually, but maybe;

Code: Select all

[measureDisplayName]
Measure=Calc
Formula=1
IfCondition=([measureChargePower] > 0)
IfTrueAction=[!SetOption meterTitle Text "[*measureName*] lädt mit [*measureChargeCurrentRequest*]A/[*measureChargePower*]KW"]
DynamicVariables=1
Enno
Posts: 5
Joined: December 25th, 2019, 8:36 am

Re: 2 Problems in 1 Code

Post by Enno »

Thanks. Fixed the Problem.
I tried to substitute the original parse string from the URL.

the string can be empty -> car is slepping
will be substituted in measureName

normal the string will be the name of the car.
But if i´m charging it schuld be added the actual charging power.
so on charging it will display:
K.I.T.T. Lädt Mit 10A/7KW

So i have 3 States:
K.I.T.T.
K.I.T.T. is charging with 10A/7KW
K.I.T.T. is sleeping


So your code fixed it. Thanks for it.
mak_kawa
Posts: 564
Joined: December 30th, 2015, 9:47 am

Re: 2 Problems in 1 Code

Post by mak_kawa »

And DynamicVariables=1 is neccesary in [meterTitle] meter.
mak_kawa
Posts: 564
Joined: December 30th, 2015, 9:47 am

Re: 2 Problems in 1 Code

Post by mak_kawa »

Probably balala will correct my post...:-)

[measureDisplayName] is not necessary at all. Ifcondition expression is better to be located in [measureChargePower] measure itself, like this.

Code: Select all

[measureChargePower]
Measure=Plugin
Plugin=WebParser
URL=[measureSite]
StringIndex=4
IfCondition=(measureChargePower > 0)
IfTrueAction=[!SetOption meterTitle Text "[*measureName*] lädt mit [*measureChargeCurrentRequest*]A/[*measureChargePower*]KW"]
mak_kawa
Posts: 564
Joined: December 30th, 2015, 9:47 am

Re: 2 Problems in 1 Code

Post by mak_kawa »

For the 2nd. problem...Again I am not sure what [measureodometerKmt], [measureodometerKmh] and [measureodometerKmk] measures mean. But generally speaking, to add leading zero to [measureodometerKmh], use RegExpSubstitute.

Code: Select all

[measureodometerKmh]
Measure=Calc
Formula=Trunc(Frac(measureodometer*1.60934 / 1000)*1000)
RegExpSubstitute=1
Substitute="^(\d{2})$":"0\1","^(\d)$":"00\1"
This substitute displays one digit with two leading zeros like "002", and two digits with one leading zero like "012".
Enno
Posts: 5
Joined: December 25th, 2019, 8:36 am

Re: 2 Problems in 1 Code

Post by Enno »

and thanks again,
this substitute works fine.


I didn´t find a way to change the odometer (Kilometer) to the local format.
Will come from teslafi.com as 14887.51675 miles
And should show as 23.959,1 Km
So i divided into:
measureodometerKmt = Odometer Thousends = 23
measureodometerKmh = Odometer hundreds = 959
measureodometerKmk = Odometer decimal place = 1
and will add in meter as: kmt.kmh,kmk
was the easiest way for me. :)

*1.60934 is miles to kilometer conversion ;)
xenium
Posts: 474
Joined: January 4th, 2018, 9:52 pm

Re: 2 Problems in 1 Code

Post by xenium »

Enno wrote:
December 25th, 2019, 1:23 pm
I didn´t find a way to change the odometer (Kilometer) to the local format.
Will come from teslafi.com as 14887.51675 miles
And should show as 23.959,1 Km
So i divided into:
measureodometerKmt = Odometer Thousends = 23
measureodometerKmh = Odometer hundreds = 959
measureodometerKmk = Odometer decimal place = 1
and will add in meter as: kmt.kmh,kmk
was the easiest way for me. :)

*1.60934 is miles to kilometer conversion ;)
Try this too:
Replace the 3 measures ([measureodometerKmt],
[measureodometerKmh], [measureodometerKmk]) and [meterodometerKm] with these:

Code: Select all

[measureodometerKm]
Measure=Calc
Formula=measureodometer * 1.609344
RegExpSubstitute=1
Substitute="^(?(?=-)-)(\d+)$":"\0A","([\.,])":"A","\d{1,3}(?=(\d{3})+A)":"\0B","A$":"","A":",","B":"."

[meterodometerKm]
Meter=String
MeterStyle=styleRightText
MeasureName=measureodometerKm
X=200
Y=0r
W=190
H=14
Text=%1 km
NumOfDecimals=1
https://forum.rainmeter.net/viewtopic.php?f=119&p=96093&hilit=quote+enclose+option#p96093