Hourly Tibber rates on matrix displays (e.g. Ulanzi TC001)

User story:
I would like to see a graphical representation of the hourly Tibber rates for today and tomorrow on a matrix display.

BOM:

Setup:

  1. Get your TC001 up and running (just follow the installation instructions).
  2. If you can’t read Chinese, I strongly recommend to switch the UI to English, see Ulanzi Desktop Pixel Clock TC001 Review | Blakadder's Smarthome Shenanigans.
  3. Install AWTRIX.
  4. Configure your TC001 as an AWTRIX controller (‘Atrix Simulator’, port 7001), see Ulanzi Desktop Pixel Clock TC001 Review | Blakadder's Smarthome Shenanigans.
  5. Use the AWTRIX UI to enable MQTT.
  6. Install lua and json-lua (sudo luarocks install json-lua).
  7. Copy the following script to your filesystem:
#!/bin/bash
mosquitto_pub -m "{\"remove\":\"TibberApp\"}" -h <MQTT broker IP address> -u <MQTT user> -P <MQTT password>  -t awtrix/temporaryapp
curl 2>/dev/null \
-H "Authorization: Bearer <your personal Tibber API token>" \
-H "Content-Type: application/json" \
-X POST \
-d '{ "query": "{ viewer { homes { currentSubscription{ priceInfo{ today { total } tomorrow { total } } } } } }" }' https://api.tibber.com/v1-beta/gql \
| lua create_awtrix_tibber_app.lua | tr -d '\n' | mosquitto_pub -l -h <MQTT broker IP address> -u <MQTT user> -P <MQTT password> -t awtrix/temporaryapp
  1. Adjust <your personal Tibber API token> and the MQTT parameters.
  2. Copy the following Lua script into create_awtrix_tibber_app.lua and place it in the same directory as the shell script:
json = require "JSON"

function print_color( p )

if p <= red
 then
  print( '  "color":[255,0,0]' )
 else
  if p <= orange
   then
    print( '  "color":[255,165,0]' )
   else
    print( '  "color":[0,255,0]' )
   end
 end

end


function analyse_day( res, today )

 red    = 0.35
 orange = 0.30

 prices = {}

 min = math.huge
 max = -math.huge

 if today
  then
   dataset = "today"
  else
   dataset = "tomorrow"
  end

 if #res["data"]["viewer"]["homes"][1]["currentSubscription"]["priceInfo"][ dataset ] == 24
  then

   for x,y in pairs( res["data"]["viewer"]["homes"][1]["currentSubscription"]["priceInfo"][ dataset ])
    do

     prices[x-1] = ( y["total"] ) * 1.0

        if prices[x-1] > max
         then

          max = prices[x-1]
      max_pos = x-1

         end

        if prices[x-1] < min
         then

          min = prices[x-1]
          min_pos = x-1

         end

   end

  diff = max - min

  red    = 7 - math.floor( ( red - min )    * 7 / diff + 0.5 )
  orange = 7 - math.floor( ( orange - min ) * 7 / diff + 0.5 )

  min_pixel = 7 - math.floor( ( min - min ) * 7 / diff + 0.5 )
  max_pixel = 7 - math.floor( ( max - min ) * 7 / diff + 0.5 )

  current_hour = os.date("*t").hour

  price_current = prices[ current_hour ]

  if not today
   then

    print(' {')
    print( '    "type": "fill",')
    print( '     "color": [50,50,50]')
    print( '   },')

   end

  if today
   then

    print( '{ "type":"pixel",' )
    print( '  "position":['..current_hour..",0]," )
    print( '  "color":[255,255,255]' )
    print( '},')

    print( '{ "type":"pixel",' )
    print( '  "position":['..current_hour..",7]," )
    print( '  "color":[255,255,255]' )
    print( '},')

   end

  for i = 0,23 do prices[i] = 7 - math.floor( ( prices[i]-min ) * 7 / diff + 0.5 ) end

  for i = 0,23
   do

    print( '{ "type":"pixel",' )
    print( '  "position":['..i..","..prices[i].."]," )

    print_color( prices[i] )

    print( '},')

   end

  if today
   then

    print( '{ "type":"text",' )
    print( '  "string":"' ..  math.floor( price_current * 100 + 0.5 )..'",')
    print( '  "position":[24,0],' )
    print_color( prices[ current_hour ] )
    print( '},')

    print( '{')
    print( '      "type": "show"')
        print( '    },')
    print( '    {')
    print( '      "type": "wait",')
    print( '      "ms": 10000')
    print( '    },')

   else

    print( '{ "type":"text",' )
    print( '  "string":"' ..  math.floor( min * 100 + 0.5 )..'",')
    print( '  "position":[24,0],' )
    print_color( min_pixel )
    print( '},')

    print( '{ "type":"pixel",' )
    print( '  "position":['..min_pos..",0]," )
    print( '  "color":[255,255,255]' )
    print( '},')

        print(' {')
    print( '    "type": "line",')
    print( '     "start": [27,7],')
    print( '     "end": [29,7],')
    print( '     "color": [255,255,255]')
    print( '   },')
    print(' {')
    print( '    "type": "pixel",')
    print( '     "position": [28,6],')
    print( '     "color": [255,255,255]')
    print( '   },')

    print( '   {')
    print( '     "type": "show"')
    print( '   },')
    print( '   {')
    print( '     "type": "wait",')
    print( '     "ms": 3000')
    print( '   },')

  if not today
   then

    print(' {')
    print( '    "type": "fill",')
    print( '     "color": [50,50,50]')
    print( '   },')

        print(' {')
    print( '    "type": "line",')
    print( '     "start": [27,6],')
    print( '     "end": [29,6],')
    print( '     "color": [255,255,255]')
    print( '   },')
    print(' {')
    print( '    "type": "pixel",')
    print( '     "position": [28,7],')
    print( '     "color": [255,255,255]')
    print( '   },')

    for i = 0,23
     do

      print( '{ "type":"pixel",' )
      print( '  "position":['..i..","..prices[i].."]," )

      print_color( prices[i] )

          print( '},')

     end

   end

--[[
    for i = 0, 7
     do

      print(' {')
      print( '    "type": "line",')
      print( '     "start": [24,'..i..'],')
      print( '     "end": [31,'..i..'],')
      print( '     "color": [50,50,50]')
      print( '   },')

     end
--]]

    print( '{ "type":"text",' )
    print( '  "string":"' ..  math.floor( max * 100 + 0.5 )..'",')
    print( '  "position":[24,0],' )
    print_color( max_pixel )
    print( '},')

    print( '{ "type":"pixel",' )
    print( '  "position":['..max_pos..",7]," )
    print( '  "color":[255,255,255]' )
    print( '},')


    print( '{')
    print( '      "type": "show"')
    print( '    },')
    print( '    {')
    print( '      "type": "wait",')
    print( '      "ms": 3000')
    print( '    },')

   end

  end -- data available

end -- function analyse_day

txt = io.read( '*a' )

res = json:decode( txt )

print( '{')
print( '   "name":"TibberApp",')
print( '   "lifetime":9999,')
print( '   "drawing":true,')
print( '   "data":[')

analyse_day( res, true )
analyse_day( res, false )

print( '    {')
print( '      "type": "exit"')
print( '    }')
print( '  ]')
print( '}')

  1. Execute the shell script to test your installation. I strongly recommend to use MQTT Explorer to check the installation (topic awtrix/temporaryapp):
    grafik
    The result should look like:


    Today from 7 pm to 8 pm (current hour): 30 ct/kWh

    Tomorrow from 12 noon to 1 pm lowest rate: 23 ct/kWh:

    Tomorrow from 7 pm to 8 pm highest rate: 36 ct/kWh:

Screen #1 and screen #2 are from the AWTRIX Time App and screens #3 - #5 were created by the new temporary Tibber App for AWTRIX. The white cursor marks the current hour (screen #3) and the hour with the lowest rate (screen #4) and the hour with the highest rate (screen #5), the number in the upper right corner is the current rate (screen #3), lowest (screen #4) and highest rate (screen #5) for tomorrow (unit: ct/kWh). The thresholds for the color of the graphs and the rates can be configured in the Lua script.
11. Setup a rule or use the Exec Binding to run the shell script every hour on the hour.

I am open to suggestions on how to integrate this framework into openHAB.

Edit #1:
If you are going to use the shell script via executeCommandLine: Make sure you prepend the correct path to create_awtrix_tibber_app.lua in the shell script - it took me some time to debug my openHAB rule.

Edit #2:
Min/max rates for tomorrow added, shell script and Lua script updated.

2 Likes

hi, i tried your script, but i get this error while running it within the command line

lua: create_awtrix_tibber_app.lua:37: attempt to get length of field '?' (a nil value)
stack traceback:
	create_awtrix_tibber_app.lua:37: in function 'analyse_day'
	create_awtrix_tibber_app.lua:249: in main chunk
	[C]: ?

Most probably your Tibber API call is wrong/incomplete. Test it:

curl 2>/dev/null \
-H "Authorization: Bearer <your personal Tibber API token>" \
-H "Content-Type: application/json" \
-X POST \
-d  '{ "query": "{ viewer { homes { currentSubscription{ priceInfo{ today { total } } } } }}" }' https://api.tibber.com/v1-beta/gql

just testet it, just works fine

{"data":{"viewer":{"homes":[{"currentSubscription":{"priceInfo":{"today":[{"total":0.3164},{"total":0.2969},{"total":0.2925},{"total":0.2851},{"total":0.2828},{"total":0.2863},{"total":0.2947},{"total":0.2919},{"total":0.2821},{"total":0.2648},{"total":0.2258},{"total":0.1997},{"total":0.1983},{"total":0.189},{"total":0.1903},{"total":0.1947},{"total":0.1994},{"total":0.2227},{"total":0.2526},{"total":0.2775},{"total":0.2481},{"total":0.2255},{"total":0.2132},{"total":0.1996}]}}}]}}}

OK, shell script and Lua script in my OP didn’t match - sorry.

Replace
-d '{ "query": "{ viewer { homes { currentSubscription{ priceInfo{ today { total } } } } }}" }' https://api.tibber.com/v1-beta/gql \

with
-d '{ "query": "{ viewer { homes { currentSubscription{ priceInfo{ today { total } tomorrow { total } } } } } }" }' https://api.tibber.com/v1-beta/gql \

I have updated the shell script in my OP - thanks for finding the mismatch.

I just did this but if I now execute the script within my terminal the script never finishes. I do not get any text while executing. What can I do to debug this?
Thanks

Remove

tr -d '\n' | mosquitto_pub -l -h <MQTT broker IP address> -u <MQTT user> -P <MQTT password> -t awtrix/temporaryapp

from the shell script for testing purposes. Output should look like:

{
   "name":"TibberApp",
   "lifetime":9999,
   "drawing":true,
   "data":[
{ "type":"pixel",
  "position":[10,0],
  "color":[255,255,255]
},
{ "type":"pixel",
  "position":[10,7],
  "color":[255,255,255]
},
{ "type":"pixel",
  "position":[0,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[1,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[2,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[3,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[4,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[5,6],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[6,3],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[7,3],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[8,2],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[9,3],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[10,5],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[11,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[12,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[13,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[14,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[15,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[16,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[17,4],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[18,1],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[19,0],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[20,0],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[21,1],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[22,1],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[23,2],
  "color":[0,255,0]
},
{ "type":"text",
  "string":"19",
  "position":[24,0],
  "color":[0,255,0]
},
{
      "type": "show"
    },
    {
      "type": "wait",
      "ms": 10000
    },
    {
      "type": "exit"
    }
  ]
}

If this succeeds, check your MQTT and AWTRIX installation (cf. step 10 in my OP).

This is the output.

{
   "name":"TibberApp",
   "lifetime":9999,
   "drawing":true,
   "data":[
table: 0x742450
{ "type":"pixel",
  "position":[11,0],
  "color":[255,255,255]
},
{ "type":"pixel",
  "position":[11,7],
  "color":[255,255,255]
},
{ "type":"pixel",
  "position":[0,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[1,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[2,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[3,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[4,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[5,6],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[6,3],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[7,3],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[8,2],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[9,3],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[10,5],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[11,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[12,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[13,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[14,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[15,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[16,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[17,4],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[18,1],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[19,0],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[20,0],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[21,1],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[22,1],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[23,2],
  "color":[255,0,0]
},
{ "type":"text",
  "string":"21",
  "position":[24,0],
  "color":[0,255,0]
},
{
      "type": "show"
    },
    {
      "type": "wait",
      "ms": 10000
    },
    {
      "type": "exit"
    }
  ]
}

It looks nearly identical but why is there a

table …

in line 6?
Thanks

Shouldn’t be there and I cannot reproduce it with the Lua script in my OP. Might be a debug output from a previous version of the Lua script. Just replace your Lua script with the current one from my OP.

now the output looks fine

{
   "name":"TibberApp",
   "lifetime":9999,
   "drawing":true,
   "data":[
{ "type":"pixel",
  "position":[20,0],
  "color":[255,255,255]
},
{ "type":"pixel",
  "position":[20,7],
  "color":[255,255,255]
},
{ "type":"pixel",
  "position":[0,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[1,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[2,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[3,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[4,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[5,6],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[6,3],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[7,3],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[8,2],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[9,3],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[10,5],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[11,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[12,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[13,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[14,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[15,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[16,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[17,4],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[18,1],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[19,0],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[20,0],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[21,1],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[22,1],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[23,2],
  "color":[255,0,0]
},
{ "type":"text",
  "string":"40",
  "position":[24,0],
  "color":[255,0,0]
},
{
      "type": "show"
    },
    {
      "type": "wait",
      "ms": 10000
    },
 {
    "type": "fill",
     "color": [50,50,50]
   },
{ "type":"pixel",
  "position":[0,5],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[1,6],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[2,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[3,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[4,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[5,6],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[6,4],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[7,2],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[8,1],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[9,1],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[10,3],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[11,4],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[12,5],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[13,5],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[14,5],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[15,5],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[16,5],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[17,4],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[18,1],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[19,0],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[20,2],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[21,2],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[22,4],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[23,5],
  "color":[255,165,0]
},
{ "type":"text",
  "string":"29",
  "position":[24,0],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[3,0],
  "color":[255,255,255]
},
 {
    "type": "line",
     "start": [27,7],
     "end": [29,7],
     "color": [255,255,255]
   },
 {
    "type": "pixel",
     "position": [28,6],
     "color": [255,255,255]
   },
   {
     "type": "show"
   },
   {
     "type": "wait",
     "ms": 3000
   },
 {
    "type": "fill",
     "color": [50,50,50]
   },
 {
    "type": "line",
     "start": [27,6],
     "end": [29,6],
     "color": [255,255,255]
   },
 {
    "type": "pixel",
     "position": [28,7],
     "color": [255,255,255]
   },
{ "type":"pixel",
  "position":[0,5],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[1,6],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[2,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[3,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[4,7],
  "color":[0,255,0]
},
{ "type":"pixel",
  "position":[5,6],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[6,4],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[7,2],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[8,1],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[9,1],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[10,3],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[11,4],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[12,5],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[13,5],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[14,5],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[15,5],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[16,5],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[17,4],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[18,1],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[19,0],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[20,2],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[21,2],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[22,4],
  "color":[255,165,0]
},
{ "type":"pixel",
  "position":[23,5],
  "color":[255,165,0]
},
{ "type":"text",
  "string":"37",
  "position":[24,0],
  "color":[255,0,0]
},
{ "type":"pixel",
  "position":[19,7],
  "color":[255,255,255]
},
{
      "type": "show"
    },
    {
      "type": "wait",
      "ms": 3000
    },
    {
      "type": "exit"
    }
  ]
}

but within mqtt explorer i see the following only:
Bildschirmfoto 2023-04-11 um 20.54.30
and
Bildschirmfoto 2023-04-11 um 20.54.53
The script itself never finishes. I have to press ctrl+c to kill the script.
Any idea what is still going wrong.
Thank you very much for your great help.

edit:
do i have to put the custom app into the AppLoop within AWTRIX? or should it be displayed right away?

If

#!/bin/bash
mosquitto_pub -m "{\"remove\":\"TibberApp\"}" -h <MQTT broker IP address> -u <MQTT user> -P <MQTT password>  -t awtrix/temporaryapp
curl 2>/dev/null \
-H "Authorization: Bearer <your personal Tibber API token>" \
-H "Content-Type: application/json" \
-X POST \
-d '{ "query": "{ viewer { homes { currentSubscription{ priceInfo{ today { total } tomorrow { total } } } } } }" }' https://api.tibber.com/v1-beta/gql \
| lua create_awtrix_tibber_app.lua 

outputs the JSON for the temporary Tibber app (and does publish to awtrix/temporaryapp as your result from MQTT Explorer proves), piping the result to tr and then to mosquitto_pub should work and shouldn’t be blocking. Check your second mosquitto_pub command in the shell script for errors (correct broker IP, user, password?). No need to put the temporary app created by the Lua script into the app loop - that’s what the second call to mosquitto_pub in the shell script is for.

BTW, activeApp = Notification/CustomApp looks strange as it isn’t valid JSON.

HI,
i just found my problem.
The problem was the last mqtt publish.
Instead of

mosquitto_pub -l -h <MQTT broker IP address> -u <MQTT user> -P <MQTT password> -t awtrix/temporaryapp

for me the following is working

mosquitto_pub -s -h <MQTT broker IP address> -u <MQTT user> -P <MQTT password> -t awtrix/temporaryapp

Thanks a lot for your support

1 Like

HI,
one last question.
I would like to ad a fourth color.
Would this be correct?

if p <= red
 then
  print( '  "color":[255,0,0]' )
 else
  if p <= orange
   then
    print( '  "color":[255,165,0]' )

   else
    if p <= yellow
     then
      print( '  "color":[255,255,0]' )

     else
      print( '  "color":[0,255,0]' )
     end
   end
 end

end


function analyse_day( res, today )

 red    = 0.35
 orange = 0.30
 yellow = 0.25

So i would like to have:
pricer higher than 0.35 → red
price between 0.3 and 0.35 → orange
price between 0.25 and 0.3 → yellow
price below 0.25 → green

Thanks a lot.

You would have to add at least one additional line (search for orange to find all places in the Lua script):

yellow = 7 - math.floor( ( yellow - min ) * 7 / diff + 0.5 )

One additional remark:
The Lua script doesn’t handle switching from/to DST. It should be easy to add it to the Lua script (just check for 23 or 25 price values and …).

What do you mean with switching from/to DST?

In some regions, clocks are set forward/back once a year. This results in 23 or 25 price values. The Lua script will not work on these days.

I would like to repeat the three „images“ two times.
But if I add
repeat:2
the last image is overlayed with the first one.
So I think I need to draw an empty image for 1ms after the third image.
But everything I tried did not work.
Can you help me?
Thanks

For detailed explanations of writing AWTRIX applications, see AWTRIX. Try the clear command. However, AWTRIX is EOL and closed source, so you are on your own with AWTRIX, e.g. I couldn’t get the MQTT topic awtrix/draw to work.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.