vloschiavo/powerwall2

Configuration changes don't take affect

spoonwzd opened this issue · 2 comments

So I'm having a go at making my own script in Powershell. I'm just at the 'working the commands out stage' but it's been going well.

I am able to set the mode & reserve percentage, but the settings are not taking effect after calling /api/config/completed.

Can you offer any advice? Here's my progress:

Invoke-WebRequest -Method POST -ContentType 'application/json' -Body '{"username":"dave@internet.com","password":"ST17K0001234","force_sm_off":true}' -Uri 'http://192.168.7.7/api/login/Basic'

StatusCode        : 200
Content           : {"email":null,"firstname":"Tesla","lastname":"Energy","roles":["Provider_Engineer"],"token":"3NSFEB
                    OeOaSSvSinb98WhZsFh4MwG9fVk6-xPy2bwdam6oCvDeYi1FvTIFtV6EUCSuBQC9ZFLfCQgu1uAqG5Yw==","provider":"Bas
                    ic...

Invoke-WebRequest -Uri 'http://192.168.7.7/api/sitemaster/run'

StatusCode        : 202
Content           :

$token = '3NSFEBOeOaSSvSinb98WhZsFh4MwG9fVk6-xPy2bwdam6oCvDeYi1FvTIFtV6EUCSuBQC9ZFLfCQgu1uAqG5Yw=='
$link = 'http://192.168.7.7/api/operation'
$header = @{Authorization = 'Bearer '+$token}

Invoke-WebRequest -Method POST -Body '{"mode":"self_consumption", "backup_reserve_percent":100}' -Uri $link -headers $header

StatusCode        : 200
Content           : {"mode":"self_consumption","backup_reserve_percent":100}

Invoke-WebRequest -Uri http://192.168.7.7/api/config/completed -headers $header -Method GET

StatusCode        : 202
Content           :

So all looks good.... but it doesn't start charging from the grid!

Everything looks good to me:

Invoke-WebRequest -Uri $link -Headers $header

StatusCode        : 200
Content           : {"mode":"self_consumption","backup_reserve_percent":100}

Any ideas?

Figured it out. You have to set /api/sitemaster/run AFTER setting the operation and calling /api/config/completed.

This is now working:

$powerwallurl = 'http://192.168.7.7'
$login = Invoke-WebRequest -Method POST -ContentType 'application/json' -Body '{"username":"dave@internet.com","password":"ST17K0001234","force_sm_off":true}' -Uri $powerwallurl/api/login/Basic | ConvertFrom-JSON
$token = $login.token
$header = @{Authorization = 'Bearer '+$token}
Invoke-WebRequest -Method POST -ContentType 'application/json' -Body '{"mode":"self_consumption","backup_reserve_percent":5}' -Uri $powerwallurl/api/operation -headers $header
Invoke-WebRequest -Uri $powerwallurl/api/config/completed -headers $header
Invoke-WebRequest -Uri $powerwallurl/api/sitemaster/run