What's new

WiFi Thermostat

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

richardeid

Regular Contributor
I've spent way too long on this now. I have a thermostat. It's a Radio Thermostat CT80. I like it.

I recently decided to finally take the plunge and use Merlin firmware on my AC88U. I'm on the latest, 380.66_2. I wanted to do this because I decided to finally take a dive into the API of this thermostat so I could accomplish at a minimum, this. And maybe after a while some other fun things. I'm really a novice at scripting so I'm having some trouble taking care of this. I think I've done what I needed, but clearly not.

Initially I installed Merlin to start using Transmission, so I have entware.ng installed. According to the second link I needed to also install curl and jq (luckily that was there). So I did that. I also needed to register to use the Weather Underground API, did that. And now I'm at a weird point.

I have always heard it's better to type out the code you're going to be using instead of copy/pasting it. That's what I did with this, and just to be sure I used Notepad++ to compare it. I made a lot of mistakes copying the code initially but I think I figured out most of it now. Or not...or something. Here's my current code for those two script files. This is a direct copy/paste:
Code:
#/bin/sh

/opt/bin/curl -o /tmp/cur-conditions.json http://api.wunderground.com/api/XXXAPIKEYXXX/conditions/q/zmw:XXXXX.0.99999.json
/opt/bin/curl -d \{\"line\"\:0,\"message\":\"\Outdoor\ Temp:\ 'cat /tmp/cur-conditions.json | jq -r .current_observation.temp_f'\ RH:\ 'cat /tmp/cur-conditions.json | jq -r .current_observation.relative_humidity'\"\} http://192.168.1.3/tstat/uma
Code:
#/bin/sh

/opt/bin/curl -o /tmp/cur-forcast.json http://api.wunderground.com/api/XXXAPIKEYXXX/forecast/q/pws:XXXXXXXXXX.json
/opt/bin/curl -d \{\"line\"\:1,\"message\":\"\Today\ Hi:'cat /tmp/cur-forcast.json | jq -r .forecast.simpleforecast.forecastday[1].high.fahrenheit'\ Lo:'cat /tmp/cur-forcast.json | jq -r .forecast.simpleforecast.forecastday[1].low.fahrenheit'\ POP:'cat /tmp/cur-forcast.json | jq -r .forecast.simpleforecast.forecastday[1].pop'\%\"\} http://192.168.1.3/tstat/uma
OK so I obviously removed my API key. The zmw:XXXXX is where my zip code would go. And the pws:XXXXXXXXX is the weather station closest to my house. I've also assigned 192.168.1.3 as a static IP to that thermostat and I verified it by using the API to return some info to me through my browser. Currently, with all the "right" info in place, my thermostat display looks like this:

WP_20170522_01_14_18_Rich_LI.jpg


I've tinkered with both files for longer than I've wanted to and I think I'm ready to ask for help. The API for the thermostat and can be accessed here. The relevant bit relating to what I'm attempting is on the page numbered 8 within the PDF. The Wunderground API is here. Specifically this section and this section.

I feel like I'm right there but just don't have the knowledge to get myself the rest of the way. And at this point even if I did I wouldn't know why or how I did it because I'm pretty much playing hunt and peck with the code. Maybe one of you fine people can show me where I've gone astray.

Thanks for taking the time to read. I know this isn't a Merlin issue; It's more of a scripting issue.
 
Last edited:
Image didn't come through so not sure what issue you're having :(

A few things to check:
1. Make sure to save the file from Notepad++ using UNIX LF, and not Windows CRLF.
2. Make the scripts executable
 
Hi, thank you for responding.

I changed the link for the image so it'll take you to another page. I couldn't figure out how to direct link to OneDrive. I swear the way I used to do it worked but I guess it doesn't now.

Anyway, as to your points.

1. I initially had some trouble because I was using nano without -w so I was saving the file with some line breaks where they shouldn't be. I only used NP++ to compare the differences between what it should be vs. what it is.

2. I have the scripts in /jffs/scripts. And 'chmod a+rx /jffs/scripts/*' is right? If so, I've done that as well. FWIW I also did set up the cron job like is detailed, so those scripts are actually being pushed to cron through cru in init-start.
 
Could be a difference between ' and ` they're using ` in the example, but you're using '. ` is with ~, ' is with ".
 
Could be a difference between ' and ` they're using ` in the example, but you're using '. ` is with ~, ' is with ".
Correct. In Linux shell scripting, there are three styles of quote character. Each style does something different.

'bbbbbbbbbbb'
"ccccccccccccc"
`aaaaaaaaaaaaa` is the same as $(aaaaaaaaaaaaa)

the first one specifies an exact literal string
the second specifies a literal string and expands the $variables
the third executes a Linux shell command

lastly, if you encounter an issue with a nested variable or command, the way to solve it is to close the quote, then specify the nested variable or command, then re-open the quote
 
Last edited:
Could be a difference between ' and ` they're using ` in the example, but you're using '. ` is with ~, ' is with ".
Correct. In Linux shell scripting, there are three styles of quote character. Each style does something different.

'bbbbbbbbbbb'
"ccccccccccccc"
`aaaaaaaaaaaaa` is the same as $(aaaaaaaaaaaaa)

the first one specifies an exact literal string
the second specifies a literal string and expands the $variables
the third executes a Linux shell command
I tried that early on and I came up with some errors that resulted in no output being pushed to the thermostat at all. I've probably changed some things since but let me get my yardwork done for the day and I'll replace ' with ` again and see what happens.

I know this isn't really the right place for this, but this forum is such a good resource for everything I love so I thought maybe I'd get some responses. <3

I'll get back to you later with the results. Thank you so much.
 
Just to clarify how this works. The script runs on the router. It downloads weather information from Weather Underground and displays it on the thermostat.

I think it will work if you cut/paste as-is from the original posting. Just need that jq program available on your router. Here's a less confusing way to write those scripts.

Code:
/usr/bin/curl -s -o /tmp/cur-conditions.json https://api.wunderground.com/api/*************/conditions/q/zmw:00000.22.71431.json

/usr/bin/curl -d '{"line":0,"message":"Outdoor Temp: '$(cat /tmp/cur-conditions.json | jq -r .current_observation.temp_c)' RH: '$(cat /tmp/cur-conditions.json | jq -r .current_observation.relative_humidity)'"}' http://tstat/tstat/uma


curl -s -o /tmp/cur-forcast.json http://api.wunderground.com/api/*************/forecast/q/pws:IONTARIO1188.json

/usr/bin/curl -d '{"line":1,"message":"Today Hi:'$(cat /tmp/cur-forcast.json | jq -r .forecast.simpleforecast.forecastday[0].high.celsius)' Lo:'$(cat /tmp/cur-forcast.json | jq -r .forecast.simpleforecast.forecastday[0].low.celsius)' POP:'$(cat /tmp/cur-forcast.json | jq -r .forecast.simpleforecast.forecastday[0].pop)'%"}' http://tstat/tstat/uma
 
Last edited:
Thanks to everyone that responded. Using ` instead of ' got it going. You guys are awesome and thank you so much. I guess the combination of me using ` and all the typos caused the initial problems but just the earlier suggestion of me using ` took care of it. I was on overload and didnt' know if changes I was making were making things worse or what but just the suggestion at that point is what took care of it. <3<3<3 All around.

Just to clarify how this works. The script runs on the router. It downloads weather information from Weather Underground and displays it on the thermostat.

I think it will work if you cut/paste as-is from the original posting. Just need that jq program available on your router. Here's a less confusing way to write those scripts.

Code:
/usr/bin/curl -s -o /tmp/cur-conditions.json https://api.wunderground.com/api/*************/conditions/q/zmw:00000.22.71431.json

/usr/bin/curl -d '{"line":0,"message":"Outdoor Temp: '$(cat /tmp/cur-conditions.json | jq -r .current_observation.temp_c)' RH: '$(cat /tmp/cur-conditions.json | jq -r .current_observation.relative_humidity)'"}' http://tstat/tstat/uma


curl -s -o /tmp/cur-forcast.json http://api.wunderground.com/api/*************/forecast/q/pws:IONTARIO1188.json

/usr/bin/curl -d '{"line":1,"message":"Today Hi:'$(cat /tmp/cur-forcast.json | jq -r .forecast.simpleforecast.forecastday[0].high.celsius)' Lo:'$(cat /tmp/cur-forcast.json | jq -r .forecast.simpleforecast.forecastday[0].low.celsius)' POP:'$(cat /tmp/cur-forcast.json | jq -r .forecast.simpleforecast.forecastday[0].pop)'%"}' http://tstat/tstat/uma
I'm no pro and I've had a couple drinks but a part of me had me thinking that there was an easier way to write this out. I'll check out your code once I sober up a bit and see if that works for me.

If anyone has some fun stuff for me to try I'm totally open. I always tell myself I'm going to have that moment I always hear about where someone just "gets it' and coding ends up making sense to them. I was hoping that this was it, but so far just some typos aren't doing it for me.

Thanks to everyone that responded.

Here's my current output:

WP_20170522_20_47_49_Rich_LI.jpg


In case that image doesn't work, it's working. Thanks again!
 
Last edited:
Thanks to everyone that responded. Using ` instead of ' got it going. You guys are awesome and thank you so much. I guess the combination of me using ` and all the typos caused the initial problems but just the earlier suggestion of me using ` took care of it. I was on overload and didnt' know if changes I was making were making things worse or what but just the suggestion at that point is what took care of it. <3<3<3 All around.

Just saw this thread - and yes, punctuation matters, and so do empty spaces... and CR/LF handling can be a real mess...

Windows - Notepad++ is really good to have handy... pasting into putty should handle the CR/LF handling, but importing a file directly can lead to errors...

Putty is awesome - but also consider Mobaxterm...

Nice to see that it's all sorted there...
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top