@Override
    public void run()
    {
        while(true)
        {
            Messages.parseForMessages();
            DateTime dt = new DateTime();
            System.out.println(dt.getHourOfDay()+":"+dt.getMinuteOfHour());
            if(counteratlastsecond==-1)
                try {
                    System.out.println("counterlastsecond is -1 so we update to the current value");
                    counteratlastsecond = getCurrentValue();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            else
            {
                try
                {
                    double value = getCurrentValue();
                    if(value!=counteratlastsecond)
                    {
                        double change = value-counteratlastsecond;
                        if(change<0)
                        {
                            change=0;
                        }
                        energycouter=energycouter+change;
                        counteratlastsecond = value;
                        System.out.println("the change is: "+change);
                        if(change>0.2)
                        {
                            currentrunntime++;
                            currentdowntime=0;
                            energythisuptime=energythisuptime+change;
                            laststate=state;
                            state=STATE_ON;

                        }
                        else
                        {
                            currentrunntime=0;
                            currentdowntime++;
                            laststate=state;
                            state=STATE_OFF;
                        }
                    }
                    else
                    {
                        laststate=state;
                        currentrunntime=0;
                        currentdowntime++;
                        state=STATE_OFF;
                    }
                    System.out.println(value);
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
            checkForActions();
            if(laststate==STATE_ON && state == STATE_OFF)
            {
                energythisuptime=0;
            }
            sleep();
        }

    }