Trying to get a script to work ! To control UFH from a edit

Discussion in 'C-Bus Automation Controllers' started by max w, Dec 24, 2018.

  1. max w

    max w

    Joined:
    Sep 14, 2017
    Messages:
    24
    Likes Received:
    2
    Location:
    GB
    Hi I’m trying to get the attached script to work in a shac and edlt, it seems to work in principle.
    But the display on the edlt has not altered.
    It remains showing variable 1& 2.
    I have no faults in the error log on the shac.

    Any help would be great thanks Max W

    create a setpoint value in the start up (init) scripts.


    storage.set('setpoint', 20) --start point is 20--


    ---------------------------------------------------------------------------------------------------



    create an event based script mapped to a lighting group address to increase decrease setpoint. EDLT is set for shutter relay, lighting application, key function set to 2key with presets, set the presets to have the same value as spadjust reads below for up and down, set dynamic labels for both label and status

    variant 1 and variant 2 respectively


    -- Get level of the Lighting group 8 in the 56 application on the local network

    spadjust = GetCBusLevel(0, 56, 8)

    -- read in stored setpoint --

    newdata = storage.get('setpoint')


    if (spadjust == 2) then

    newdata = newdata -0.5

    -- set storage variable myobjectdata to a specified value (e.g. 127)

    storage.set('setpoint', newdata)

    -- Set the button back (and group address) back to 0 value --

    SetCBusLevel(0, 56, 8, 0, 0)



    elseif (spadjust == 252) then

    newdata = newdata +0.5

    -- set storage variable myobjectdata to a specified value (e.g. 127)

    storage.set('setpoint', newdata)

    -- Set the button back (and group address) back to 0 value --

    SetCBusLevel(0, 56, 8, 0, 0)

    end


    --------------------------------------------------------------------------------------------------------


    create the following resident script to read in room temp and setpoint and display them on the screen

    and to turn on the output.



    --get room temp from sensor--

    temp, units = GetCBusMeasurement(0, 253, 1)

    --round the value

    temp1 = tonumber(string.format("%." .. (1) .. "f", temp))

    --convert to a string

    temp2 = tostring(temp1)

    --format the appearance of the label

    label = ('Room Temp ' ..temp2..' '..units)

    --if temp is different the update dynamic label

    if (old_temp ~= temp1) then

    SetCBusUnicodeLabel(0, 56, 8, 'English', 'Variant2', label)

    old_temp = temp1

    else

    end


    --read in setpoint and convert to a string

    set_temp = storage.get('setpoint')

    set_temp1 = tostring(set_temp)

    --format the appearance of the label

    set_label = ('SetPoint ' ..set_temp1..' '..units)

    --if temp is different the update dynamic label

    if (old_set_temp ~= set_temp1) then

    SetCBusUnicodeLabel(0, 56, 8, 'English', 'Variant1', set_label)

    old_set_temp = set_temp1

    else

    end


    -- compare values and turn the load on or off

    if set_temp > temp1 then

    SetCBusLevel(0, 56, 10, 255, 4)

    elseif set_temp <= temp1 then

    SetCBusLevel(0, 56, 10, 0, 0)

    end
     
    max w, Dec 24, 2018
    #1
  2. max w

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    248
    Likes Received:
    31
    Location:
    New Zealand
    Hi Max w,

    I have done this a different way but i have it working

    setpoint ga in the switch make an event script for then store value in a user parameter, kind of like system io in piced, you will need to create a user parameter called Set Point.

    -- in event script for setpoint up/down control
    local level = CBusLevelToPct(event.getvalue())
    local current_value = GetUserParam(0, 'Set Point')

    --setpoint_update
    if (level == 0) then
    current_value = current_value -1
    SetUserParam(0, 'Set Point', current_value )
    SetCBusUnicodeLabel(0, 56, setpoint_ga, 'English', 1, 'Set Pt ' .. setpoint_current_value .. '°C')
    ----log (current_value)
    end

    if (level == 99) then
    current_value =current_value + 1
    SetUserParam(0, 'Set Point', current_value)
    SetCBusUnicodeLabel(0, 56, setpoint_ga, 'English', 1, 'Set Pt ' .. setpoint_current_value .. '°C')
    ----log (current_value)
    end

    now your setpoint value is stored into the user parameter and the temp written to the EDLT then all you need is to grab the temp and then make your changes.
    is your temp sensor set up to be on the measurement application in the SHAC if so set up an object, i had to do this manually as when i imported the CGL file from toolkit this didnt come across
    once you have the sensor set up as an individual object you can query etc.

    the way i have done it was to set the broadcast on the 5104DTSI to broadcast the temp every time the temp changes by 1° i also have another script on the Heat On_Off Ga to check the setpoint and temp each time the ga is turned off and on and make the required changes to the heater etc

    Then i have an event script for the temp sensor object as below

    local temp = event.getvalue()
    local offset = 1


    if GetLightingState("Heat On_Off") == true then

    -- update the current temp label to variant 2 on the setpoint up/down GA
    SetCBusUnicodeLabel(0, 56, Setpoint_ga, 'English', 2, 'temp ' .. temp .. '°C')

    local setpoint = GetUserParam(0, 'Set Point')

    if temp <= setpoint + offset then
    -- heater on
    SetLightingState('Heater', true)
    end

    if setpoint <= temp then
    -- heater off
    if GetLightingState('Heater') == 255 then
    SetLightingState('Heater', false)
    end
    end

    end
     
    Pie Boy, Jan 2, 2019
    #2
  3. max w

    max w

    Joined:
    Sep 14, 2017
    Messages:
    24
    Likes Received:
    2
    Location:
    GB

    Thanks Pie Boy I will give it a go once I get back to work !
     
    max w, Jan 5, 2019
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.