Using % in data field

Moderator: leecollings

Post Reply
lukev
Posts: 66
Joined: Friday 21 October 2016 10:42
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Using % in data field

Post by lukev »

Hello all,

I would like to make a blocky to notify me when my iphone is almost charged. I have a script that reads out the battery percentage, but this is written in the DATA field. So I guess this is a string instead of an integer...
Is it possible make such a blocky?

Here's the readout of the IDX:

Code: Select all

{
   "ActTime" : 1497470123,
   "ServerTime" : "2017-06-14 21:55:23",
   "Sunrise" : "05:22",
   "Sunset" : "21:57",
   "result" : [
      {
         "AddjMulti" : 1.0,
         "AddjMulti2" : 1.0,
         "AddjValue" : 0.0,
         "AddjValue2" : 0.0,
         "BatteryLevel" : 255,
         "CustomImage" : 0,
         "Data" : "47.00%",
         "Description" : "",
         "Favorite" : 0,
         "HardwareID" : 119,
         "HardwareName" : "Iphone battery",
         "HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
         "HardwareTypeVal" : 15,
         "HaveTimeout" : false,
         "ID" : "00082853",
         "Image" : "Computer",
         "LastUpdate" : "2017-06-14 21:50:04",
         "Name" : "iPhone Battery Luke",
         "Notifications" : "false",
         "PlanID" : "0",
         "PlanIDs" : [ 0 ],
         "Protected" : false,
         "ShowNotifications" : true,
         "SignalLevel" : "-",
         "SubType" : "Percentage",
         "Timers" : "false",
         "Type" : "General",
         "TypeImg" : "hardware",
         "Unit" : 1,
         "Used" : 1,
         "XOffset" : "0",
         "YOffset" : "0",
         "idx" : "853"
      }
   ],
   "status" : "OK",
   "title" : "Devices"
}
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Using % in data field

Post by Egregius »

Think it will be hard in Blockly to do this, in php on the other hand:

Code: Select all

<?php
$iphone=json_decode(file_get_contents('http://127.0.0.1:8080/json.htm?type=devices&rid=853'),true);
if(isset($iphone['result'][0]['Data'])){
    if(str_replace('%','',$iphone['result'][0]['Data'])>85)telegram('iPhone almost charged');
} 
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest